Skip to content

[WIP] [#521] Research Agent Tools#524

Draft
sahilds1 wants to merge 3 commits into
CodeForPhilly:developfrom
sahilds1:521-research-agent-tools
Draft

[WIP] [#521] Research Agent Tools#524
sahilds1 wants to merge 3 commits into
CodeForPhilly:developfrom
sahilds1:521-research-agent-tools

Conversation

@sahilds1

Copy link
Copy Markdown
Collaborator

Description

Related Issue

Manual Tests

Automated Tests

Documentation

Reviewers

Notes

@sahilds1 sahilds1 self-assigned this Jul 15, 2026
@sahilds1 sahilds1 changed the title Research Agent Tools [WIP] [#521] Research Agent Tools Jul 15, 2026
@sahilds1
sahilds1 marked this pull request as draft July 15, 2026 22:50
sahilds1 added 2 commits July 16, 2026 15:10
Add ask_database as a second tool for the assistant, alongside the
existing semantic search_documents tool.

- Reuse the SELECT-only, ALLOWED_TABLES-guarded ask_database
  implementation from services/tools/database.py rather than
  reimplementing the query guards in the assistant.
- Add get_tools_schema() / make_tool_mapping() as an aggregation seam
  in tool_services.py so assistant_services.py no longer names
  individual tools; new tools are registered in one place.
- Build the ask_database schema in the flattened Responses-API shape
  (not the nested Chat Completions shape from services/tools), and
  defer the database_schema_string import to call time so importing
  the module never triggers a DB query.
- Split tool_services.py: move search_documents into search_tool.py and
  the agentic-loop helpers (handle_tool_calls_with_reasoning,
  invoke_functions_from_response) into agentic_loop.py, adding the
  imports each module needs.
- Point importers (assistant_services.py, test_tool_services.py) at the
  defining module for each symbol instead of re-exporting through
  tool_services.py.
- Document the search/SQL tool overlap risk and the import-time DB
  access caveat inline.
Replace the two parallel tool registries (get_tools_schema /
make_tool_mapping) with a single Tool dataclass and a TOOLS list, so each
tool's schema and callable live under one name and can't drift apart.

- Add Tool(name, description, parameters, run) with a .schema() method;
  define SEARCH_TOOL and ASK_DATABASE_TOOL instances and a single TOOLS
  list as the source of truth. Adding a tool is appending one Tool.
- Build the ask_database schema from Medication._meta (concrete_fields /
  db_table) instead of introspecting the live database, removing the
  import-time DB query and the deferred database_schema_string import.
- Bind the request user at dispatch time: invoke_functions_from_response
  and handle_tool_calls_with_reasoning now take (tools, user), index
  tools by name, and call tool.run(user=user, **arguments). This drops
  make_tool_mapping / make_search_tool_mapping and their closures.
- assistant_services builds the schema list with
  [tool.schema() for tool in TOOLS] and forwards TOOLS + user to the loop.
- Update tests to cover the Tool instances and pass (tools, user) to the
  loop; the tool_services.search_documents / ask_database patch paths
  still resolve.
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.

1 participant