feat: migrate timestamp extension to a2a 1.0 (#525) · a2aproject/a2a-samples@df18eed · GitHub
Skip to content

Commit df18eed

Browse files
authored
feat: migrate timestamp extension to a2a 1.0 (#525)
1. Migrate to a2a 1.0 alpha 3. 1. Replace referencing this package from other samples with a folder-local test. **Note:** required fixing ruff for those files as they were added to diff and ruff got executed, seems like they were not clean before and had many ruff violations.
1 parent 5fa24f7 commit df18eed

11 files changed

Lines changed: 1585 additions & 210 deletions

File tree

‎pyproject.toml‎

Lines changed: 0 additions & 1 deletion

‎samples/python/agents/adk_expense_reimbursement/__main__.py‎

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import logging
22
import os
3+
import sys
34

45
import click
6+
import uvicorn
57

68
from a2a.server.apps import A2AStarletteApplication
79
from a2a.server.request_handlers import DefaultRequestHandler
@@ -10,7 +12,6 @@
1012
from agent import ReimbursementAgent
1113
from agent_executor import ReimbursementAgentExecutor
1214
from dotenv import load_dotenv
13-
from timestamp_ext import TimestampExtension
1415

1516

1617
load_dotenv()
@@ -19,29 +20,23 @@
1920
logger = logging.getLogger(__name__)
2021

2122

22-
class MissingAPIKeyError(Exception):
23-
"""Exception for missing API key."""
24-
25-
2623
@click.command()
2724
@click.option('--host', default='localhost')
2825
@click.option('--port', default=10002)
29-
def main(host, port):
30-
try:
31-
# Check for API key only if Vertex AI is not configured
32-
if not os.getenv('GOOGLE_GENAI_USE_VERTEXAI') == 'TRUE':
33-
if not os.getenv('GEMINI_API_KEY'):
34-
raise MissingAPIKeyError(
35-
'GEMINI_API_KEY environment variable not set and GOOGLE_GENAI_USE_VERTEXAI is not TRUE.'
36-
)
37-
38-
hello_ext = TimestampExtension()
39-
capabilities = AgentCapabilities(
40-
streaming=True,
41-
extensions=[
42-
hello_ext.agent_extension(),
43-
],
26+
def main(host: str, port: int) -> None:
27+
"""Start the reimbursement agent server."""
28+
# Check for API key only if Vertex AI is not configured.
29+
if os.getenv('GOOGLE_GENAI_USE_VERTEXAI') != 'TRUE' and not os.getenv(
30+
'GEMINI_API_KEY'
31+
):
32+
logger.error(
33+
'GEMINI_API_KEY environment variable not set and '
34+
'GOOGLE_GENAI_USE_VERTEXAI is not TRUE.'
4435
)
36+
sys.exit(1)
37+
38+
try:
39+
capabilities = AgentCapabilities(streaming=True)
4540
skill = AgentSkill(
4641
id='process_reimbursement',
4742
name='Process Reimbursement Tool',
@@ -61,25 +56,18 @@ def main(host, port):
6156
capabilities=capabilities,
6257
skills=[skill],
6358
)
64-
agent_executor = ReimbursementAgentExecutor()
65-
# Use the decorator version of the extension for highest ease of use.
66-
agent_executor = hello_ext.wrap_executor(agent_executor)
6759
request_handler = DefaultRequestHandler(
68-
agent_executor=agent_executor,
60+
agent_executor=ReimbursementAgentExecutor(),
6961
task_store=InMemoryTaskStore(),
7062
)
7163
server = A2AStarletteApplication(
7264
agent_card=agent_card, http_handler=request_handler
7365
)
74-
import uvicorn
7566

7667
uvicorn.run(server.build(), host=host, port=port)
77-
except MissingAPIKeyError as e:
78-
logger.error(f'Error: {e}')
79-
exit(1)
80-
except Exception as e:
81-
logger.error(f'An error occurred during server startup: {e}')
82-
exit(1)
68+
except Exception:
69+
logger.exception('An error occurred during server startup')
70+
sys.exit(1)
8371

8472

8573
if __name__ == '__main__':

‎samples/python/agents/adk_expense_reimbursement/pyproject.toml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ dependencies = [
1111
"google-genai>=1.27.0",
1212
"python-dotenv>=1.1.0",
1313
"litellm",
14-
"timestamp_ext",
1514
]
1615

1716
[tool.hatch.build.targets.wheel]
@@ -20,6 +19,3 @@ packages = ["."]
2019
[build-system]
2120
requires = ["hatchling"]
2221
build-backend = "hatchling.build"
23-
24-
[tool.uv.sources]
25-
timestamp_ext = { workspace = true }

‎samples/python/extensions/timestamp/pyproject.toml‎

Lines changed: 13 additions & 1 deletion

0 commit comments

Comments
 (0)