how to create ai agents

developer2026-10-22

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

Price per call, developer tools Horizontal bar chart of the price per call and the cache-hit price, in US dollars, for 12 developer tools. The same values are in the table below the chart. Price per call Cache-hit price $0.0 $0.0005 $0.001 Usage Time SeriesUsage Time Series $0.0 $0.0 Per-Tool Usage BreakdownPer-Tool Usage Breakdown $0.0 $0.0 Usage SummaryUsage Summary $0.0 $0.0 Discover ToolsDiscover Tools $0.0 $0.0 Batch Tool CallsBatch Tool Calls $0.0 $0.0 Tool Quality MetricsTool Quality Metrics $0.0 $0.0 Tool Quality RankingsTool Quality Rankings $0.0 $0.0 List Programming LanguagesList Programming Languages $0.001 $0.0001 Check CVE ID Reservation Stat…Check CVE ID Reservation Status $0.001 $0.0001 Security Advisories (deps.dev)Security Advisories (deps.dev) $0.001 $0.0001 Dependency Tree (deps.dev)Dependency Tree (deps.dev) $0.001 $0.0001 Package Info (deps.dev)Package Info (deps.dev) $0.001 $0.0001 US dollars per call
Price per call for developer tools, cheapest first.

Data source: live tool catalog snapshot, fetched 2026-10-22.

Chart data as a table
ToolPrice per callCache-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
ToolProviderPrice/callCache-hit
Usage Time Seriesaccount$0$0
Per-Tool Usage Breakdownaccount$0$0
Usage Summaryaccount$0$0
Discover Toolsapibase$0$0
Batch Tool Callsplatform$0$0
Tool Quality Metricsplatform$0$0
Tool Quality Rankingsplatform$0$0
List Programming Languagesjudge0$0.001$0.0001
Check CVE ID Reservation Statuscve-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

How a tool call worksAn AI agent sends a tool call to the APIbase gateway. The gateway checks payment, calls the provider API, and returns the JSON result to the agent.Your agentAPIbase gatewayProvider API1. tool call2. paid call3. JSON result flows back to the agent
Diagram: the path of one tool call.

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.

  1. STEP 1/2 Connect your MCP client
  2. STEP 2/2 Browse the full catalog

Published: 2026-10-22Source: live apibase.pro catalog snapshot