Skip to content

Conversation

@psx95
Copy link
Contributor

@psx95 psx95 commented Jul 15, 2025

Sample adopted from https://github.com/aabmass/opentelemetry-operations-python/tree/adk-sample/samples/adk-sql-agent.

Testing

  • Generates & exports traces to Google Cloud via OTLP.
  • Creates a per session database, multiple sessions work simultaneously each with their isolated copy of sqlite database.

TODO

  • Add region tags to support documentation.

@psx95 psx95 requested a review from a team as a code owner July 15, 2025 18:30
@snippet-bot
Copy link

snippet-bot bot commented Jul 15, 2025

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@psx95 psx95 requested a review from aabmass July 15, 2025 18:30
Copy link
Collaborator

@aabmass aabmass left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great thank you!

@tracer.start_as_current_span("run_sql")
def run_sql_tool(sql_query: str, tool_context: ToolContext) -> dict[str, Any]:
"""Runs a SQLite query. The SQL query can be DDL or DML. Returns the rows if it's a SELECT query."""
current_session_db_path = tool_context.state[SESSION_DB_KEY]
Copy link
Collaborator

@aabmass aabmass Jul 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check if this is None (model hasn't decided to create the session yet) and return error? I think as is it would throw an exception but I'm not sure how ADK handles tool call exceptions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can certainly do that, but, the model should figure out what tool to use and use it accordingly - if the dbpath is null, then the model should invoke the create_database tool to create one before executing the query.

If we start anticipating exceptions then we should also validate the sql_query before executing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did some experiments -
Added a tool that always raises exception. It halts the agent's response. It is recommended to always return structured responses from tools even in case of exception.

Based on this, I added a return statement to the create_db tool and added a check. LLM should be able to read the responses and recover.

@psx95 psx95 merged commit 454662b into GoogleCloudPlatform:main Jul 21, 2025
20 checks passed
@psx95 psx95 deleted the add-adk-sample branch July 21, 2025 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants