[langgraph]创建第一个agent
我一直想看看agent到底是怎么建起来的。
langchain ->langgraph
pip install -U langgraph “langchain[anthropic]”
Then, create an agent using prebuilt components:
# pip install -qU "langchain[anthropic]" to call the modelfrom langgraph.prebuilt import create_react_agentdef get_weather(city: str) -> str:"""Get weather for a given city."""return f"It's always sunny in {city}!"agent = create_react_agent(model="anthropic:claude-3-7-sonnet-latest",tools=[get_weather],prompt="You are a helpful assistant"
)# Run the agent
agent.invoke({"messages": [{"role": "user", "content": "what is the weather in sf"}]}
)