Also known as Programmatic Tool Calling (PTC)Documentation Index
Fetch the complete documentation index at: https://www.truefoundry.com/llms.txt
Use this file to discover all available pages before exploring further.
What is Code Mode?
Code Mode uses the Sandbox to let the agent write code to chain tool calls with arbitrary logic. The agent is provided with utilties to inspect output schema of tools and a mcp client inside the sandbox to allow listing, inspecting and calling allowed tools programmatically.- Programmatic tool calls — The Agent writes Python in the sandbox to call MCP tools and work with the response in code:
When does Agent use Code Mode?
Aggregate or format tool output
Use case: The user wants open PRs grouped by contributor with a count for each author.- With Code Mode — The Agent calls the tool inside a script, groups or aggregates in code (for example
Counteron author login), and prints only the summary table. - Without Code Mode — The full tool response is added to the conversation. The model must read every PR object and produce counts per author in natural language.
- Context bloat — Dozens of PR records with titles, labels, and metadata fill the context even though the user only asked for counts.
- Hallucination — The model can miscount PRs per author, merge two usernames, or invent a contributor who is not in the response. Group-by and count tasks are especially error-prone when done from prose rather than code.
User
How many open PRs does each contributor have on
truefoundry/docs-mintlify?Assistant
Let me check the output schema for the GitHub list-pull-requests tool, then count PRs per author in one script.
The Agent calls
get_tool_output_schema so it knows the shape of the tool response before writing Code Mode scripts. With a defined outputSchema, the model can read and transform fields in code safely instead of guessing keys or types from raw JSON.get_tool_output_schema
get_tool_output_schema
Tool CallTool Response
Assistant
sandbox
sandbox
Tool CallTool Response
Assistant
On
truefoundry/docs-mintlify there are 7 open PRs across 4 contributors: alice-dev (3), bob-eng (2), carol-docs (1), and deb-docs (1).Chain tool calls
Use case: The user wants to know what metrics are available for appmy-app in the tfy-test-cluster:test-ws workspace.
- With Code Mode — The Agent runs
list_applicationsandlist_app_metric_chartsin one script. It findsmy-appin the first response, passes the appidandworkspaceIdinto the second call, and prints only the chart table. - Without Code Mode — The Agent calls the first tool, waits for a model turn, then must copy IDs and other fields from the JSON into the second tool call.
- Context bloat — The full
list_applicationsresponse (pagination, metadata, every app field) sits in the conversation before the second call runs. - Longer to finish — Each tool hop needs another model call in between, which adds latency.
- Hallucination — The model can typo an
applicationIdorworkspaceId, pick the wrong app from a long list, or drop a required field so the second call fails or returns the wrong charts.
- Context bloat — The full
User
What metrics are available for app
my-app in the tfy-test-cluster:test-ws workspace?Assistant
I need schemas for
list_applications and list_app_metric_charts, then I will resolve the app and list its charts in one script.The Agent calls
get_tool_output_schema so it knows the shape of the tool response before writing Code Mode scripts. With a defined outputSchema, the model can read and transform fields in code safely instead of guessing keys or types from raw JSON.get_tool_output_schema
get_tool_output_schema
Tool CallTool Response
get_tool_output_schema
get_tool_output_schema
Tool CallTool Response
Assistant
sandbox
sandbox
Tool CallTool Response
Assistant
my-app in
tfy-test-cluster:test-ws has 12 metric charts (CPU, memory, network, request volume, and others). Query step is 1800s.