How to Build an AI Agent
An AI agent is a language model that can call tools in a loop toward a goal. To build one, pick a model, connect tools, often through MCP, write the instructions and the loop, add memory, and set limits on what it can do. A Solana trading agent is the worked example.
What an AI agent is (and isn't)
A chatbot answers in one turn. An agent keeps going: it calls a tool, reads what came back, and calls another tool until it stops. How to create an AI agent is the same shape, whether you write the loop or a host already has one.
| Chatbot | AI agent | |
|---|---|---|
| What it does | Writes a reply from the conversation | Calls tools in a loop toward a goal |
| Memory | This chat, unless you paste notes back in | Can read notes, files or a saved plan next time |
| Side effects | None, unless you copy the answer somewhere | A tool can read data or place an order |
| What stops it | The reply ends | A stop rule, an approval, or a limit outside the model |
Step by step
Five steps. The trading example later uses the same five.
Step 1: Pick a model
Choose a model you can call from a host or from your own code. The model is the part that reads the goal and decides the next tool call. Compare Grok, ChatGPT, Claude and Codex for trading research.
Step 2: Give it tools
Tools are how the agent acts. MCP, the Model Context Protocol, is one way to attach them: the host calls a server, and the server returns data or takes an action. Read tools and write tools are different risks. See MCP for trading and MCP vs an API.
Step 3: Write the instructions and the loop
Write the goal, the order of checks, and when to stop. The loop is: read the state, call a tool, read the result, decide again. A prompt is not a limit. The loop should end when the goal is met or a stop rule fires.
Step 4: Add memory
A chat disappears when the session ends. Memory is the notes the agent can read next time: what it already checked, what you approved, and which plan is running. Keep secrets out of that memory.
Step 5: Set guardrails
Put caps, approvals and a way to stop the agent outside the model. If the only control is the conversation, a bad tool call can still go out. For an agent that spends money, the service that accepts the order should enforce the limits. The framework is on AI agent guardrails and AI agent security.
No-code vs code
No code: use a host that already runs the loop, and attach an MCP server. Hosts here are Codex, Claude Code (CLI), Gemini CLI (with a paid Gemini API key or enterprise access) and Grok CLI with the agent key. In ChatGPT, paste your personal Moby connector URL from the app. ChatGPT: works on Business, Enterprise and Edu workspaces that allow custom MCP servers (web).
Code: you write the loop, the tool calls and the memory store yourself, in a framework or from scratch.
Frameworks such as ElizaOS and the Solana Agent Kit are compared in build a Solana trading agent.
A harness is the always-on runner around a model. That comparison is the harness guide.
Worked example: a trading agent
An AI agent for trading, also called an AI trading agent, is the same five steps with a tool that can place orders. Connect Moby MCP from a supported host. Codex, Claude Code (CLI), Gemini CLI (with a paid Gemini API key or enterprise access) and Grok CLI with the agent key. In ChatGPT, paste your personal Moby connector URL from the app. ChatGPT: works on Business, Enterprise and Edu workspaces that allow custom MCP servers (web).
You set your agent's limits on max per trade, daily buy volume and market-cap range from the Moby app, and Moby checks them server-side on every buy your agent makes.
Each user gets one agent, with its own wallet, separate from the main in-app wallet. Fund that wallet in USDC. Agents trade Solana tokens, including tokenized stocks. Agent trading on Base, BNB Chain and Robinhood Chain is coming soon.
Give it a strategy prompt from agent strategies, or follow a walkthrough on tutorials. Tell your agent your exits and it places real take-profit and stop-loss orders on Moby, including a one-call bracket.
Building the bot around data, strategy and execution is a different page: how to build an AI trading bot. This page is the agent: model, tools, loop, memory and guardrails. The wider pattern is agentic trading.
Common mistakes
- No limits. A sentence in the prompt is not a cap. The service that accepts the order has to check it.
- A key pasted on the command line. Put the agent key in an environment variable, as Moby Agents shows:
read -rs MOBY_API_KEY && export MOBY_API_KEY, thenAuthorization: Bearer $MOBY_API_KEY. Do not paste the key into a chat. - No log. If you cannot see what the agent called, you cannot tell a bad tool result from a bad decision.
- Trusting tool output blindly. A tool description can be poisoned. That case is covered in whether a poisoned MCP tool description can trick a trading agent.
FAQ
Do I need to code to build an AI agent?
No. You can use a host that already runs the loop, such as Codex, Claude Code (CLI), Grok CLI or Gemini CLI, and connect tools through MCP. You can also write the loop yourself in code. Both are agents. The difference is who maintains the loop.
How much does it cost to build an AI agent?
There is no single price. A host may charge for its own plan. A trading service charges its own fees. On Moby, A 0.75% swap fee (minimum $0.90 per swap), plus onchain fees.
What is MCP?
MCP, the Model Context Protocol, is an open way for an AI app to call tools on a server. The host sends a request. The server returns data or takes an action. MCP for trading explains read tools and write tools.
Can an AI agent trade for me?
Yes, if a connected tool can place orders, and only inside the limits that tool enforces. On Moby, each user has one agent, with its own wallet, funded in USDC. Agents trade Solana tokens, including tokenized stocks. Agent trading on Base, BNB Chain and Robinhood Chain is coming soon.
What does Moby charge?
A 0.75% swap fee (minimum $0.90 per swap), plus onchain fees.
Try it with a Moby Agent
You set your agent's limits on max per trade, daily buy volume and market-cap range from the Moby app, and Moby checks them server-side on every buy your agent makes.
A 0.75% swap fee (minimum $0.90 per swap), plus onchain fees.
Start at Moby Agents. The product frame is agentic trading.
Trading crypto and tokenized stocks is risky and you can lose money. Nothing on this page is investment advice.