how to create ai agents
On this page
An AI agent is a language model that runs in a loop. It reads a goal and calls tools. It reads each result and chooses the next step until it can answer. To build one, start with a model that supports tool calling. Define each tool with a name and typed inputs. Run a loop that executes the calls the model requests. Cap the number of turns. MCP tools for developers let you attach ready-made tools instead of writing each integration by hand.
What an AI agent is
An agent has three parts: a model, a set of tools, and a loop. The model reads the goal and picks the next action. The tools do the work, such as searching a database or calling an API. The loop sends each tool result back to the model.
A chatbot answers with text only. An agent acts. It can look up an order, check a stock level, or open a support ticket, then report what it did. The action step is the reason to build an agent instead of a prompt.
Pick a model that supports tool calling
Choose a model with native tool calling. The model returns a structured request that names a tool and its arguments. Your code runs the tool and returns the output. Models without this feature can still follow a text format, but parsing errors become common.
Test two or three candidate models on your real goals. Compare the tool calls they produce, not only the final answers. A model that picks the right tool on the first try lowers both cost and latency.
Build the agent loop
The loop is the core of the agent. Most loops follow the same four steps:
- Send the goal and the tool definitions to the model.
- If the model returns a tool call, run that tool with the arguments it supplied.
- Append the tool result to the conversation.
- Repeat until the model returns text with no tool call, or until the turn limit stops the run.
A loop of a few dozen lines handles many agents. Log each tool call with its arguments and its result. The log shows where the agent chose a wrong step.
Define tools the model can call
Each tool needs a name, a plain description, and a typed input schema. The description tells the model when to pick the tool. Write it for the model, not for a code reviewer.
Narrow tools work better than broad ones. A tool named get_order_status with a single order_id field gives the model less room for error than a tool that accepts raw SQL. Return only the fields the model needs. Large outputs fill the context window and slow each later turn.
Attach tools through MCP
The Model Context Protocol gives agents a standard way to discover and call tools. An MCP client asks a server which tools exist, reads their schemas, and calls them by name. Each tool you write yourself becomes one more integration to maintain.
APIbase is an MCP gateway with a large and growing catalog. It spans many categories and hundreds of providers. Connect your agent once, then select the tools your use case needs. Start on the connect page.
Keep the tool list short. Attach only the tools the agent needs for its current task. A smaller list gives the model fewer wrong choices.
Add limits, logging and tests
An agent without limits can repeat a failing call forever. Add these controls before you run it with real data:
- Cap the number of loop turns in code.
- Set a timeout on each tool call.
- Validate tool arguments before the call runs.
- Require human approval for any action that writes data or spends money.
Write a small test set of goals with the tool calls you expect. Check the sequence of calls, not only the final text. A correct answer can still hide a wasted or unsafe tool call. Run the test set after each prompt or tool change.
What it costs to run
Costs come from model tokens, tool usage, and your own hosting. Token use grows with each loop turn, so a shorter loop costs less. Tool outputs add tokens too, which is one more reason to return only the fields the model needs.
APIbase plans range from 0 USD to 29.99 USD. Your model provider bills model costs separately.
Common mistakes when building agents
Most failed agents break in the same few ways:
- The agent gets too many tools at once, so the model picks the wrong one.
- Tool descriptions stay vague, so the model cannot tell when to use each tool.
- The loop has no turn limit, so a failing call repeats.
- Tool outputs return full records, so the context window fills up.
Fix the tool set first. Most agent failures trace back to a tool the model could not use well. Change the prompt only after the tools work on their own.
Live pricing — developer
Data source: live tool catalog snapshot, fetched 2026-10-22.
Chart data as a table
| Tool | Price per call | Cache-hit price |
|---|---|---|
| Usage Time Series | $0.0 | $0.0 |
| Per-Tool Usage Breakdown | $0.0 | $0.0 |
| Usage Summary | $0.0 | $0.0 |
| Discover Tools | $0.0 | $0.0 |
| Batch Tool Calls | $0.0 | $0.0 |
| Tool Quality Metrics | $0.0 | $0.0 |
| Tool Quality Rankings | $0.0 | $0.0 |
| List Programming Languages | $0.001 | $0.0001 |
| Check CVE ID Reservation Status | $0.001 | $0.0001 |
| Security Advisories (deps.dev) | $0.001 | $0.0001 |
| Dependency Tree (deps.dev) | $0.001 | $0.0001 |
| Package Info (deps.dev) | $0.001 | $0.0001 |
| Tool | Provider | Price/call | Cache-hit |
|---|---|---|---|
| Usage Time Series | account | $0 | $0 |
| Per-Tool Usage Breakdown | account | $0 | $0 |
| Usage Summary | account | $0 | $0 |
| Discover Tools | apibase | $0 | $0 |
| Batch Tool Calls | platform | $0 | $0 |
| Tool Quality Metrics | platform | $0 | $0 |
| Tool Quality Rankings | platform | $0 | $0 |
| List Programming Languages | judge0 | $0.001 | $0.0001 |
| Check CVE ID Reservation Status | cve-mitre | $0.001 | $0.0001 |
| Security Advisories (deps.dev) | depsdev | $0.001 | $0.0001 |
| Dependency Tree (deps.dev) | depsdev | $0.001 | $0.0001 |
| Package Info (deps.dev) | depsdev | $0.001 | $0.0001 |
Connect via MCP
Data source: gateway design, no measured values.
$ curl -X POST https://apibase.pro/api/v1/tools/account.timeseries/call \
-H "Content-Type: application/json" -d '{"params": {}}'FAQ
Do I need a framework to create an AI agent?
No. A plain loop that calls the model and runs its tool requests is enough for many agents. Frameworks add helpers for memory, retries and tracing. Those helpers matter once the agent grows. Start with the loop. Add a framework only when you need its features.
What is the difference between an agent and a workflow?
A workflow runs fixed steps in a set order. An agent chooses its next step at runtime based on tool results. Use a workflow when the steps never change. Use an agent when the right next step depends on what the tools return.
Which programming language should I use?
Use the language your team already ships. The loop, tool definitions and tool calls work the same way in any language with an HTTP client and JSON support. Pick the language that your team can debug and maintain without extra work.
How much does it cost to run an agent?
Cost depends on model tokens and tool usage. APIbase pricing starts at 0 USD and reaches 29.99 USD, depending on the plan. Shorter loops and smaller tool outputs reduce token use, which lowers the model bill.
Can an agent run without a person reviewing each step?
Yes, for read-only tasks. Add approval gates for any action that writes data, sends messages or spends money. Log every tool call with its arguments and result, so you can audit each run after it finishes.
Recommended next step
- STEP 1/2 Connect your MCP client
- STEP 2/2 Browse the full catalog
Related guides
Published: 2026-10-22Source: live apibase.pro catalog snapshot