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
4 changes: 4 additions & 0 deletions .github/workflows/python_samples_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ jobs:
python -m pip install --upgrade pip
pip install uv

- name: Check Formatting
working-directory: samples/agent/adk
run: uv run pyink --check .

- name: Build contact_lookup
working-directory: samples/agent/adk/contact_lookup
run: uv build .
Expand Down
132 changes: 69 additions & 63 deletions samples/agent/adk/contact_lookup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,77 +34,83 @@


class MissingAPIKeyError(Exception):
"""Exception for missing API key."""
"""Exception for missing API key."""


@click.command()
@click.option("--host", default="localhost")
@click.option("--port", default=10003)
def main(host, port):
try:
# Check for API key only if Vertex AI is not configured
if not os.getenv("GOOGLE_GENAI_USE_VERTEXAI") == "TRUE":
if not os.getenv("GEMINI_API_KEY"):
raise MissingAPIKeyError(
"GEMINI_API_KEY environment variable not set and GOOGLE_GENAI_USE_VERTEXAI is not TRUE."
)

capabilities = AgentCapabilities(
streaming=True,
extensions=[get_a2ui_agent_extension()],
try:
# Check for API key only if Vertex AI is not configured
if not os.getenv("GOOGLE_GENAI_USE_VERTEXAI") == "TRUE":
if not os.getenv("GEMINI_API_KEY"):
raise MissingAPIKeyError(
"GEMINI_API_KEY environment variable not set and GOOGLE_GENAI_USE_VERTEXAI"
" is not TRUE."
)
skill = AgentSkill(
id="find_contact",
name="Find Contact Tool",
description="Helps find contact information for colleagues (e.g., email, location, team).",
tags=["contact", "directory", "people", "finder"],
examples=["Who is David Chen in marketing?", "Find Sarah Lee from engineering"],
)

base_url = f"http://{host}:{port}"

agent_card = AgentCard(
name="Contact Lookup Agent",
description="This agent helps find contact info for people in your organization.",
url=base_url, # <-- Use base_url here
version="1.0.0",
default_input_modes=ContactAgent.SUPPORTED_CONTENT_TYPES,
default_output_modes=ContactAgent.SUPPORTED_CONTENT_TYPES,
capabilities=capabilities,
skills=[skill],
)

agent_executor = ContactAgentExecutor(base_url=base_url)

request_handler = DefaultRequestHandler(
agent_executor=agent_executor,
task_store=InMemoryTaskStore(),
)
server = A2AStarletteApplication(
agent_card=agent_card, http_handler=request_handler
)
import uvicorn

app = server.build()

app.add_middleware(
CORSMiddleware,
allow_origin_regex=r"http://localhost:\d+",
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.mount("/static", StaticFiles(directory="images"), name="static")

uvicorn.run(app, host=host, port=port)
except MissingAPIKeyError as e:
logger.error(f"Error: {e}")
exit(1)
except Exception as e:
logger.error(f"An error occurred during server startup: {e}")
exit(1)
capabilities = AgentCapabilities(
streaming=True,
extensions=[get_a2ui_agent_extension()],
)
skill = AgentSkill(
id="find_contact",
name="Find Contact Tool",
description=(
"Helps find contact information for colleagues (e.g., email, location,"
" team)."
),
tags=["contact", "directory", "people", "finder"],
examples=["Who is David Chen in marketing?", "Find Sarah Lee from engineering"],
)

base_url = f"http://{host}:{port}"

agent_card = AgentCard(
name="Contact Lookup Agent",
description=(
"This agent helps find contact info for people in your organization."
),
url=base_url, # <-- Use base_url here
version="1.0.0",
default_input_modes=ContactAgent.SUPPORTED_CONTENT_TYPES,
default_output_modes=ContactAgent.SUPPORTED_CONTENT_TYPES,
capabilities=capabilities,
skills=[skill],
)

agent_executor = ContactAgentExecutor(base_url=base_url)

request_handler = DefaultRequestHandler(
agent_executor=agent_executor,
task_store=InMemoryTaskStore(),
)
server = A2AStarletteApplication(
agent_card=agent_card, http_handler=request_handler
)
import uvicorn

app = server.build()

app.add_middleware(
CORSMiddleware,
allow_origin_regex=r"http://localhost:\d+",
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

app.mount("/static", StaticFiles(directory="images"), name="static")

uvicorn.run(app, host=host, port=port)
except MissingAPIKeyError as e:
logger.error(f"Error: {e}")
exit(1)
except Exception as e:
logger.error(f"An error occurred during server startup: {e}")
exit(1)


if __name__ == "__main__":
main()
main()
4 changes: 2 additions & 2 deletions samples/agent/adk/contact_lookup/a2ui_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# a2ui_schema.py

A2UI_SCHEMA = r'''
A2UI_SCHEMA = r"""
{
"title": "A2UI Message Schema",
"description": "Describes a JSON payload for an A2UI (Agent to UI) message, which is used to dynamically construct and update user interfaces. A message MUST contain exactly ONE of the action properties: 'beginRendering', 'surfaceUpdate', 'dataModelUpdate', or 'deleteSurface'.",
Expand Down Expand Up @@ -785,4 +785,4 @@
}
}
}
'''
"""
Loading
Loading