Skip to content
Merged
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
28 changes: 11 additions & 17 deletions a2a/a2a_currency_converter/app/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import httpx
import uvicorn
from dotenv import load_dotenv
from starlette.routing import Route

from a2a.server.apps import A2AStarletteApplication
from a2a.server.request_handlers import DefaultRequestHandler
from a2a.server.tasks import InMemoryPushNotifier, InMemoryTaskStore
from a2a.server.tasks import (
BasePushNotificationSender,
InMemoryPushNotificationConfigStore,
InMemoryTaskStore,
)
from a2a.types import (
AgentCapabilities,
AgentCard,
Expand All @@ -37,7 +40,7 @@ def main(host, port):
try:
# We don't check OPENAI_API_KEY here. We want the agent pod to run even if OPENAI_API_KEY isn't defined.

capabilities = AgentCapabilities(streaming=True, pushNotifications=True)
capabilities = AgentCapabilities(streaming=True, push_notifications=True)
skill = AgentSkill(
id="convert_currency",
name="Currency Exchange Rates Tool",
Expand All @@ -51,34 +54,25 @@ def main(host, port):
# Allow env var AGENT_ENDPOINT to override the URL in the agent card
url=os.getenv("AGENT_ENDPOINT", f"http://{host}:{port}/"),
version="1.0.0",
defaultInputModes=CurrencyAgent.SUPPORTED_CONTENT_TYPES,
defaultOutputModes=CurrencyAgent.SUPPORTED_CONTENT_TYPES,
default_input_modes=CurrencyAgent.SUPPORTED_CONTENT_TYPES,
default_output_modes=CurrencyAgent.SUPPORTED_CONTENT_TYPES,
capabilities=capabilities,
skills=[skill],
)

# --8<-- [start:DefaultRequestHandler]
httpx_client = httpx.AsyncClient()
push_config_store = InMemoryPushNotificationConfigStore()
request_handler = DefaultRequestHandler(
agent_executor=CurrencyAgentExecutor(),
task_store=InMemoryTaskStore(),
push_notifier=InMemoryPushNotifier(httpx_client),
push_config_store=push_config_store,
push_sender=BasePushNotificationSender(httpx_client, push_config_store),
)
server = A2AStarletteApplication(agent_card=agent_card, http_handler=request_handler)

app = server.build()

# Add the new agent-card.json path alongside the legacy agent.json path
app.routes.insert(
0,
Route(
"/.well-known/agent-card.json",
server._handle_get_agent_card,
methods=["GET"],
name="agent_card_new",
),
)

uvicorn.run(app, host=host, port=port)
# --8<-- [end:DefaultRequestHandler]

Expand Down
14 changes: 7 additions & 7 deletions a2a/a2a_currency_converter/app/agent_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ async def execute(
task = new_task(context.message)
logger.info(f"Created task for message : {context.message}")
event_queue.enqueue_event(task)
updater = TaskUpdater(event_queue, task.id, task.contextId)
updater = TaskUpdater(event_queue, task.id, task.context_id)
try:
async for item in self.agent.stream(query, task.contextId):
async for item in self.agent.stream(query, task.context_id):
is_task_complete = item["is_task_complete"]
require_user_input = item["require_user_input"]

Expand All @@ -64,7 +64,7 @@ async def execute(
TaskState.working,
new_agent_text_message(
item["content"],
task.contextId,
task.context_id,
task.id,
),
)
Expand All @@ -74,7 +74,7 @@ async def execute(
TaskState.input_required,
new_agent_text_message(
item["content"],
task.contextId,
task.context_id,
task.id,
),
final=True,
Expand Down Expand Up @@ -104,7 +104,7 @@ async def execute(
TaskState.input_required,
new_agent_text_message(
msg,
task.contextId,
task.context_id,
task.id,
),
final=True,
Expand All @@ -127,7 +127,7 @@ async def execute(
TaskState.input_required,
new_agent_text_message(
msg,
task.contextId,
task.context_id,
task.id,
),
final=True,
Expand All @@ -142,7 +142,7 @@ async def execute(
# We don't show the error to the user, as it may have credentials
"""Internal error on the agent.
Use `kubectl -n <namespace> logs deployment/<agent-name>` for details""",
task.contextId,
task.context_id,
task.id,
),
final=True,
Expand Down
2 changes: 1 addition & 1 deletion a2a/a2a_currency_converter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Sample LangGraph currency agent with A2A Protocol"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"a2a-sdk>=0.2.5,<0.3.0",
"a2a-sdk[http-server]>=0.2.5,<0.4.0",
"click>=8.1.8",
"httpx>=0.28.1",
"langchain-google-genai>=2.0.10",
Expand Down
Loading