Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion samples/python/agents/langgraph/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ data: {"id":"6d12d159-ec67-46e6-8d43-18480ce7f6ca","jsonrpc":"2.0","result":{"co

- [A2A Protocol Documentation](https://a2a-protocol.org/)
- [LangGraph Documentation](https://langchain-ai.github.io/langgraph/)
- [Frankfurter API](https://www.frankfurter.app/docs/)
- [Frankfurter API](https://frankfurter.dev/docs/)
- [Google Gemini API](https://ai.google.dev/gemini-api)


Expand Down
25 changes: 16 additions & 9 deletions samples/python/agents/langgraph/app/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@

import httpx

from langchain.agents import create_agent
from langchain.agents.structured_output import ToolStrategy
from langchain_core.messages import AIMessage, ToolMessage
from langchain_core.tools import tool
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from langgraph.prebuilt import create_react_agent
from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer
from pydantic import BaseModel


memory = MemorySaver()


@tool
def get_exchange_rate(
currency_from: str = 'USD',
Expand All @@ -37,7 +36,7 @@ def get_exchange_rate(
"""
try:
response = httpx.get(
f'https://api.frankfurter.app/{currency_date}',
f'https://api.frankfurter.dev/v1/{currency_date}',
params={'from': currency_from, 'to': currency_to},
)
response.raise_for_status()
Expand All @@ -59,6 +58,14 @@ class ResponseFormat(BaseModel):
message: str


# Allow the checkpointer to restore the structured response between turns.
memory = MemorySaver(
serde=JsonPlusSerializer(
allowed_msgpack_modules=[(ResponseFormat.__module__, ResponseFormat.__name__)]
)
)


class CurrencyAgent:
"""CurrencyAgent - a specialized assistant for currency convesions."""

Expand All @@ -79,7 +86,7 @@ class CurrencyAgent:
def __init__(self):
model_source = os.getenv('model_source', 'google')
if model_source == 'google':
self.model = ChatGoogleGenerativeAI(model='gemini-2.0-flash')
self.model = ChatGoogleGenerativeAI(model='gemini-3.8-flash')
else:
self.model = ChatOpenAI(
model=os.getenv('TOOL_LLM_NAME'),
Expand All @@ -89,12 +96,12 @@ def __init__(self):
)
self.tools = [get_exchange_rate]

self.graph = create_react_agent(
self.graph = create_agent(
self.model,
tools=self.tools,
checkpointer=memory,
prompt=self.SYSTEM_INSTRUCTION,
response_format=(self.FORMAT_INSTRUCTION, ResponseFormat),
system_prompt=f'{self.SYSTEM_INSTRUCTION} {self.FORMAT_INSTRUCTION}',
response_format=ToolStrategy(ResponseFormat),
)

async def stream(self, query, context_id) -> AsyncIterable[dict[str, Any]]:
Expand Down
2 changes: 1 addition & 1 deletion samples/python/agents/langgraph/app/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def main() -> None:

base_url = 'http://localhost:10000'

async with httpx.AsyncClient() as httpx_client:
async with httpx.AsyncClient(timeout=60.0) as httpx_client:
# Initialize A2ACardResolver
resolver = A2ACardResolver(
httpx_client=httpx_client,
Expand Down
7 changes: 4 additions & 3 deletions samples/python/agents/langgraph/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ requires-python = ">=3.12"
dependencies = [
"click>=8.1.8",
"httpx>=0.28.1",
"langchain-google-genai>=2.0.10",
"langgraph>=0.3.18",
"langchain-openai>=0.1.0",
"langchain>=1.0.0",
"langchain-google-genai>=3.0.0",
"langgraph>=1.0.0",
"langchain-openai>=1.0.0",
"pydantic>=2.10.6",
"python-dotenv>=1.1.0",
"uvicorn>=0.34.2",
Expand Down
Loading
Loading