diff --git a/a2a/a2a_currency_converter/app/__main__.py b/a2a/a2a_currency_converter/app/__main__.py index 9a3403f..1981b5d 100644 --- a/a2a/a2a_currency_converter/app/__main__.py +++ b/a2a/a2a_currency_converter/app/__main__.py @@ -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, @@ -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", @@ -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] diff --git a/a2a/a2a_currency_converter/app/agent_executor.py b/a2a/a2a_currency_converter/app/agent_executor.py index 999477b..6f6332a 100644 --- a/a2a/a2a_currency_converter/app/agent_executor.py +++ b/a2a/a2a_currency_converter/app/agent_executor.py @@ -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"] @@ -64,7 +64,7 @@ async def execute( TaskState.working, new_agent_text_message( item["content"], - task.contextId, + task.context_id, task.id, ), ) @@ -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, @@ -104,7 +104,7 @@ async def execute( TaskState.input_required, new_agent_text_message( msg, - task.contextId, + task.context_id, task.id, ), final=True, @@ -127,7 +127,7 @@ async def execute( TaskState.input_required, new_agent_text_message( msg, - task.contextId, + task.context_id, task.id, ), final=True, @@ -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 logs deployment/` for details""", - task.contextId, + task.context_id, task.id, ), final=True, diff --git a/a2a/a2a_currency_converter/pyproject.toml b/a2a/a2a_currency_converter/pyproject.toml index a686c43..51aad16 100644 --- a/a2a/a2a_currency_converter/pyproject.toml +++ b/a2a/a2a_currency_converter/pyproject.toml @@ -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",