Skip to content

feat(agent): count tool calls and failures per tool - #2

Open
ivanmilevtues wants to merge 1 commit into
mainfrom
test/tool-call-stats
Open

ivanmilevtues wants to merge 1 commit into
mainfrom
test/tool-call-stats

Conversation

@ivanmilevtues

Copy link
Copy Markdown
Member

Test PR for the one-file CodeBoarding setup (webview earendil-works#210 / action earendil-works#143), on a repository that keeps its analysis in main. Adds a small tool-call-stats module that the agent loop records into, so the review has a new component and relations to report. Not meant to merge.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T19:31:30.364639Z d537fb8 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

CodeBoarding review

Status: 2 changed components

See the full change in CodeBoarding.

graph LR
    n_Coding_Agent_Application["Coding Agent Application"]
    n_AI_Model_Providers_and_Runtime["AI Model Providers and Runtime"]
    n_Durable_Execution_Engine["Durable Execution Engine"]
    n_Protocol_and_Service_Mesh["Protocol and Service Mesh"]
    n_Terminal_User_Interface_Framework["Terminal User Interface Framework"]
    n_Build_and_Maintenance_Scripts["Build and Maintenance Scripts"]
    n_Model_Context_Protocol_Client["Model Context Protocol Client"]
    n_Codemode_Sandbox_Runtime["Codemode Sandbox Runtime"]
    n_Telemetry_Instrumentation["Telemetry Instrumentation"]
    n_Coding_Agent_Application -- "queries models and configures agent execution v…" --> n_AI_Model_Providers_and_Runtime
    n_Coding_Agent_Application -- "renders terminal interface with" --> n_Terminal_User_Interface_Framework
    n_Coding_Agent_Application -- "configures workflows and extensions in" --> n_Durable_Execution_Engine
    n_Coding_Agent_Application -- "establishes connections and binds services via" --> n_Protocol_and_Service_Mesh
    n_Coding_Agent_Application -- "authorizes and communicates through" --> n_Model_Context_Protocol_Client
    n_Coding_Agent_Application -- "executes sandboxed code via" --> n_Codemode_Sandbox_Runtime
    n_AI_Model_Providers_and_Runtime -- "prompts user login via" --> n_Coding_Agent_Application
    n_Durable_Execution_Engine -- "invokes model runtime completions in" --> n_Coding_Agent_Application
    n_Durable_Execution_Engine -- "queries model configurations from" --> n_AI_Model_Providers_and_Runtime
    n_Durable_Execution_Engine -- "utilizes context and serialization utilities fr…" --> n_Protocol_and_Service_Mesh
    n_Protocol_and_Service_Mesh -- "hosts and manages services defined in" --> n_Coding_Agent_Application
    n_Protocol_and_Service_Mesh -- "replicates committed state from" --> n_Durable_Execution_Engine
    n_Terminal_User_Interface_Framework -- "triggers user interface rendering in" --> n_Coding_Agent_Application
    n_Build_and_Maintenance_Scripts -- "verifies and generates catalog definitions from" --> n_AI_Model_Providers_and_Runtime
    n_Build_and_Maintenance_Scripts -- "invokes session and storage utilities in" --> n_Coding_Agent_Application
    n_Build_and_Maintenance_Scripts -- "manages session documents via" --> n_Durable_Execution_Engine
    n_Model_Context_Protocol_Client -- "persists OAuth credentials via" --> n_Coding_Agent_Application
    n_Codemode_Sandbox_Runtime -- "calls back into tool execution in" --> n_Coding_Agent_Application
    classDef added fill:#1f883d,stroke:#0b5d23,color:#ffffff;
    classDef modified fill:#bf8700,stroke:#7d4e00,color:#ffffff;
    classDef deleted fill:#cf222e,stroke:#82071e,color:#ffffff,stroke-dasharray:5 3;
    class n_AI_Model_Providers_and_Runtime modified;
Loading

download artifacts · run 38079936451

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d537fb8ae3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

? await failToolCallsFromTruncatedMessage(toolCalls, emit)
: await executeToolCalls(currentContext, message, config, signal, emit);
toolResults.push(...executedToolBatch.messages);
for (const result of executedToolBatch.messages) recordToolCall(result.toolName, result.isError);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Count calls made through runToolCall

When a tool invokes another tool through the exported runToolCall() pipeline, the nested call never reaches this block, so only the outer tool is counted. This occurs in packages/coding-agent/src/core/agent-session.ts, where nested tool calls delegate directly to runToolCall(); for example, a codemode call that invokes read twice records one codemode call and zero read calls or failures. Record outcomes in the common runToolCall/finalization path, while avoiding double-counting model-issued calls.

Useful? React with 👍 / 👎.

errors: number;
}

const stats = new Map<string, ToolCallStat>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Isolate counters per agent session

When multiple Agent instances run in the same Node process, this singleton map merges their calls even though agent state and sessionId are instance-specific. A session reading getToolCallStats() therefore reports tools and failures from unrelated sessions, and calling resetToolCallStats() for one session erases the other sessions' totals, including concurrent runs. Store the counters on the agent/run or key the read, record, and reset APIs by session.

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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