Copy
Ask AI
import asyncio
from langchain_anthropic import ChatAnthropic
from langchain_core.tools import tool
from langchain_adk import LlmAgent, Runner, InMemorySessionService
from langchain_adk.events.event import Event, EventType
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return f"The weather in {city} is sunny and 22 degrees."
agent = LlmAgent(
name="WeatherAgent",
llm=ChatAnthropic(model="claude-haiku-4-5-20251001"),
tools=[get_weather],
instructions="You are a helpful weather assistant.",
)
runner = Runner(
agent=agent,
app_name="demo",
session_service=InMemorySessionService(),
)
async def main():
async for event in runner.astream(
user_id="user-1",
session_id="session-1",
new_message="What's the weather in Copenhagen and Berlin?",
):
if event.is_final_response():
print(event.text)
asyncio.run(main())
Copy
Ask AI
export ANTHROPIC_API_KEY=sk-ant-...
uv run python examples/basic_agent.py