[Forge] Instrument all tool calls with DB logging

← All Specs

[Forge] Instrument all tool calls with DB logging

Goal

Wrap every tool function in tools.py with a decorator/wrapper that logs to tool_calls table (inputs, outputs, timing, success/failure). Update research_topic() and any tools used in orchestrator.

Acceptance Criteria

☐ After an analysis, tool_calls shows which tools were invoked, inputs, outputs, timing.

Approach

  • Read AGENTS.md and relevant source files
  • Understand existing code patterns before modifying
  • Implement changes following existing conventions (f-string HTML, SQLite, Bedrock Claude)
  • Test: curl affected pages, verify rendering, run scidex status
  • Commit atomically with descriptive message
  • Work Log

    2026-04-01 19:38 PT — Slot 12

    • Started task: Instrument all tool calls with DB logging
    • Read AGENTS.md, tools.py, scidex_orchestrator.py
    • Checked database: tool_calls table does not exist yet
    • Found 9 tool functions to instrument:
    - pubmed_search, pubmed_abstract
    - semantic_scholar_search
    - get_gene_info, get_disease_info
    - search_trials
    - enrichr_analyze
    - open_targets_associations
    - research_topic (convenience wrapper)
    • Plan:
    1. Create tool_calls table schema
    2. Create decorator to log inputs, outputs, timing, success/failure
    3. Apply decorator to all tool functions
    4. Test with a sample analysis

    Verification

    2026-04-26 04:20 PT — Verification

    All acceptance criteria are satisfied on main (commit 30f121046):

    Evidence:

    • tool_calls table exists in PostgreSQL with 32,784 rows across 133 distinct tools
    • 143 @log_tool_call decorators applied throughout scidex/forge/tools.py
    • research_topic() is decorated at line 6760 (@log_tool_call def research_topic(...))
    • scidex_orchestrator.py imports tools from tools module (line 58) — all instrumented
    • Live DB query confirms tool_research_topic entries with inputs, outputs, timing:

    skill_id: tool_research_topic
      input_json: {"args": ["mitochondrial transfer mechanisms query"], "kwargs": {}}
      output_json: {"topic": "...", "pubmed_papers": [...], "semantic_scholar_papers": [...], "total_evidence": N}
      duration_ms: 2895, status: success

    • 16 tool_pubmed_search, 9 tool_search_trials, 6 tool_paper_corpus_search calls logged with analysis_id
    Conclusion: Already implemented — this task was superseded by prior work in scidex/forge/tools.py and scidex/agora/scidex_orchestrator.py that applied @log_tool_call to all Forge tools including research_topic().

    Tasks using this spec (1)
    [Forge] Instrument all tool calls with DB logging
    Forge done P80
    File: 11eda21a_ff4_instrument_all_tool_spec.md
    Modified: 2026-04-25 23:40
    Size: 2.8 KB