Learn how to use TrueFoundry’s Agent API to integrate MCP servers into your applications for tool-using AI assistants.
web_search
tool to find image generation models and provide recommendations.
integration_fqn
:
headers
field. Works for both registered servers (integration_fqn
) and external servers (url
).
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
model | string | ✓ | - | The LLM model to use (e.g., “openai/gpt-4o”) |
messages | array | ✗ | - | Array of message objects with role and content |
mcp_servers | array | ✗ | - | Array of MCP Server configurations (see below) |
max_tokens | number | ✗ | - | Maximum number of tokens to generate |
temperature | number | ✗ | - | Controls randomness in the response (0.0 to 2.0) |
top_p | number | ✗ | - | Nucleus sampling parameter (0.0 to 1.0) |
top_k | number | ✗ | - | Top-k sampling parameter |
stream | boolean | ✗ | - | Whether to stream responses (only true is supported) |
iteration_limit | number | ✗ | 5 | Maximum tool call iterations (1-20) |
iteration_limit
sets the maximum number of such loops per request to prevent runaway chains.mcp_servers
array should include:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
integration_fqn | string | ✗* | - | Fully qualified name of the MCP Server integration |
url | string | ✗* | - | URL of the MCP server (must be valid URL) |
headers | object | ✗ | - | HTTP headers to send to the MCP server |
enable_all_tools | boolean | ✗ | true | Whether to enable all tools for this server |
tools | array | ✗ | - | Array of specific tools to enable |
integration_fqn
or url
must be provided, but not both.
tools
array should include:
Parameter | Type | Required | Description |
---|---|---|---|
name | string | ✓ | The name of the tool as it appears in the MCP server |
role: "tool"
, tool_call_id
, and content
) to carry tool outputs.Event | Relevant Fields | Description |
---|---|---|
Content | delta.role (first or every chunk), delta.content | Assistant text streamed over multiple chunks |
Tool Call (start) | delta.tool_calls[].function.name , delta.tool_calls[].id | Announces a function call and its id |
Tool Call (args) | delta.tool_calls[].function.arguments | Arguments streamed in multiple chunks; concatenate |
Tool Result | delta.role == "tool" , delta.tool_call_id , delta.content | Tool output tied to a tool call id |
Done | choices[].finish_reason == "stop" | Signals end of a message |
Content events: assistant text
role
on every chunk:delta.content
across chunks to build the full assistant message.Tool call events: function name then arguments
function.arguments
fragments per index
to reconstruct full arguments.finish_reason: "tool_calls"
."arguments": ""
). When invoking the tool, their API expects a valid JSON object. Normalize empty arguments to {}
before issuing the call.Tool result events: tool output
delta.role == "tool"
indicates a tool result chunk.content
is a JSON string; parse it to extract text or structured data if needed.Error events
Agent API Code Snippet - Button
Agent API Code Snippet - Example
/api/llm/agent
path which directly targets the Agent API.get_messages
function processes the streaming response to reconstruct complete messages. Let’s break it down:
role: "tool"
and include a tool_call_id
that links the result back to the specific tool call that generated it.
index
to handle multiple simultaneous tool callsarguments
string as it streams in (like {"query": "Python tutorials"}
)""
for tool arguments, but the OpenAI format expects "{}"
for empty JSON objects. We normalize this.
Complete working code
[DONE]
message indicating completion