Skip to content

One Turn, One Tool Call

How does a model’s proposed action become an observation the model can use? This chapter follows one integration test in the public Rust source for Codex CLI 0.172.0. Read the architecture overview for the surrounding components.

Evidence. Source and upstream test inspected. A separate 0.172.0 CLI probe ran the same teaching command against a local scripted provider and checked result delivery in the second request. Run the CLI probe

A thread holds the conversation state. A turn starts work against that state and can make several model requests before it completes. Additional steering input can join the same turn. App Server submits input through start_or_steer_turn. The integration test uses the same core method directly, and the regular task runs the turn through run_turn. App Server submission · Regular task

The fixture scripts two responses from a mock model server. The first requests exec_command with echo tool harness. The second returns the assistant message “all done.” Codex executes the command between those responses. Test setup

User input
→ model request 1
← function_call: exec_command, call_id = exec-command-tool-call
→ command execution: echo tool harness
→ model request 2 includes function_call_output with the same call_id
← final assistant message
→ TurnComplete
Step What the code does
Build the request run_turn takes a snapshot of conversation history for the sampling request. The Prompt type holds ordered input items, tool definitions, and base instructions. History snapshot · Prompt fields
Decode the call ToolRouter::build_tool_call converts the model’s FunctionCall into a ToolCall, carrying forward the tool name, arguments, and call_id. The output handler records the call, queues execution, and marks the turn as needing follow-up. Call conversion · Output handler
Execute the action ExecCommandHandler selects the execution environment, parses the arguments, and prepares the command for the process manager. The command’s output becomes the observation for this call. Command handler
Feed back the result The sampling code drains tool results into conversation history. The next iteration takes a new history snapshot, now including the tool output. Once the turn has resolved its follow-up work, the loop enters its completion checks. Collect results · Record results · Completion path

After receiving TurnComplete, the test inspects the mock server’s captured second request. It looks for an input item of type function_call_output with the expected call_id and verifies that the returned text reports exit code 0 and contains the line tool harness. The assertion checks delivery at the provider boundary, where the next model call receives its input. This chapter traces the fixture and its assertions from source. Request lookup · Test assertions

The mock supplies both the tool choice and final wording. The test therefore isolates the harness’s execution and result delivery. A live-model evaluation would answer a different question about whether the model selects an appropriate tool and interprets its output correctly.

In the downloadable example, look up exec-command-tool-call in two places. The provider event’s item.arguments names the command. In the next request, the input item with type function_call_output carries the exit status and output as text. A call ID can match even when execution fails. The checker therefore verifies both the ID and the reported outcome. Provider event · Next request

The Research Lab lets you change the ID while keeping the output fixed. Scripted call · Call ID lookup

What makes a tool result usable at the next decision? In a task that reads a versioned data file, a read could return successfully with the correct call ID and still contain the wrong file version. A controlled study could hold the call ID and response shape fixed while changing only the version, then measure whether a consumer proceeds, requests the right input, or flags the mismatch.

  1. Why does the fixture need two model requests within one turn?
  2. Which assertion would fail if the command ran but its output was recorded under a different call ID?

Answers. The first response proposes the call, and the second request carries the result for the next decision. The output lookup on the second request would fail to find the expected function_call_output item.

Continue with Prompt Construction and Tool Declarations to see how the available tools reach the model in the first place.