🔑
Get your Incredible API key
Generate your API key to start using this endpoint
→
Overview
The Agent API enables autonomous AI systems that can decide when and how to use tools (functions) to accomplish complex tasks. Unlike simple conversational endpoints, agents can break down multi-step problems, call appropriate tools, and use the results to provide comprehensive answers. What makes agents special:- Tool awareness - Agents understand what tools are available and when to use them
- Multi-step reasoning - Can plan and execute complex workflows
- Autonomous decision-making - Decides which tools to call and in what order
- Result integration - Uses tool outputs to inform subsequent actions and final responses
- Data lookup and retrieval - Query databases, search APIs, fetch external data
- Calculations and analysis - Perform computations, analyze data, generate reports
- External integrations - Interact with third-party services, send notifications, create records
- Workflow automation - Orchestrate multi-step business processes
- Dynamic content generation - Fetch real-time data to generate accurate, current responses
Using Agent
The Agent endpoint enables autonomous tool calling through a simple request-response pattern:- Initial Request - You send messages and define available tools
- Agent Planning - The model analyzes the request and decides which tools to call
- Tool Call Response - The API returns tool calls with arguments (doesn’t execute them)
- Your Execution - Your application executes the tool calls in your environment
- Follow-up Request - You send the tool results back to the agent
- Final Response - The agent uses tool results to generate the final answer
Examples
role (“user” or “assistant”) and content. The agent uses this context to understand the task and previous interactions. For multi-turn workflows, include previous tool call results in the message history so the agent can build on prior actions.
What are tools? An array of tool definitions the agent can choose to call. Each tool needs three things:
- name - Clear identifier (e.g.,
"get_weather","search_database") using snake_case - description - Natural language explanation of what the tool does, its capabilities, limitations, and when to use it. Be specific—this is critical for the agent’s decision-making
- input_schema - JSON Schema defining the tool’s parameters with
type,properties, andrequiredfields
system_prompt parameter to define the agent’s behavior, personality, and constraints. The system prompt is passed as a separate parameter, not as part of the messages array. For example: system_prompt="You are a helpful assistant with access to tools. Always verify information with the search tool before answering. Be concise and cite your sources."
Optional: Streaming - Set stream: true to watch the agent’s thinking process, tool calls, and responses in real-time. See the Streaming section below for details.
Working with Files in Agent Workflows
Agents can access file content when making tool calling decisions:Streaming Agent Responses
Agent streaming is particularly powerful because it provides visibility into the agent’s decision-making process. You can watch in real-time as the agent:- Reasons through the problem (
thinkingevents) - Decides which tools to call (
tool_callevents) - Generates its final response (
contentevents)
- Debugging - See exactly how the agent interprets tasks and why it chooses certain tools
- User Experience - Show users what’s happening during complex multi-step workflows
- Early Intervention - Detect and handle issues before the agent completes its full response
- Progress Indication - Provide real-time feedback for long-running agent tasks
stream: true:
thinking- Agent’s reasoning process in real-timetool_call- Tool call requests as they’re decidedcontent- Text response chunks as they’re generateddone- Signals completion of the streamerror- Any errors that occurred during generation
- See the agent’s decision-making process live
- Detect tool calls immediately without waiting
- Provide real-time feedback to users
- Handle long-running agent workflows efficiently
Response
Tool Execution Pattern
Implementing agentic workflows requires a specific pattern for handling tool calls. Here’s the complete flow with implementation guidance:Step 1: Initial Request
Send your user’s message along with tool definitions:Step 2: Check for Tool Calls
The agent analyzes the request and decides if tools are needed:Step 3: Execute Tools
Your application executes the requested tools in your environment. This is where you maintain security, rate limiting, and control:Step 4: Send Results Back
Add the tool results to the conversation and make a follow-up request:Step 5: Final Response
The agent processes the tool results and generates a comprehensive answer:Complete Example: Interactive Calculator Agent
Here’s a complete, runnable example that demonstrates the full agent loop with tool calling:Best Practices
Tool Design:- Keep tools focused - each tool should do one thing well
- Write clear, detailed descriptions - they’re critical for agent decision-making
- Include examples in descriptions when behavior might be ambiguous
- Validate inputs before execution - don’t trust the agent’s arguments blindly
- Always handle tool execution failures gracefully
- Return error messages to the agent so it can adapt
- Implement timeouts for long-running tools
- Consider fallback strategies when tools fail
- Never expose dangerous operations directly as tools
- Implement authorization checks before executing tools
- Sanitize tool inputs to prevent injection attacks
- Rate limit tool executions to prevent abuse
- Log tool calls for audit trails
- Execute independent tool calls in parallel when possible
- Cache tool results for repeated queries
- Set reasonable timeout limits
- Consider async execution for slow tools
- Use streaming to show progress during multi-step workflows
- Provide clear feedback when tools are being executed
- Allow users to cancel long-running agent tasks
- Display tool call details for transparency
