To build an AI agent, pick one job with a clear result, give the agent tools, write its instructions, require approval on any tool that changes data, deploy it and read its logs. This tutorial builds a deal coach agent in Tray Helix, which runs the agent with your app, enforces approval and logs every run.
The deal coach lives in a sales app. It reads a deal, finds what puts it at risk and tells the rep what to do next. The screens are from the agent running in Tray Helix. If you want the definition first, read what an AI agent is. If you want the product page, it is Tray Helix Agents.
The build, in order
- 1
Pick one job
Write it as a result you can check.
- 2
Give it tools
Each read or action is one tool with typed inputs.
- 3
Write the instructions
Say what good looks like and what to refuse.
- 4
Choose the model
Name one, and list fallbacks.
- 5
Add approval and limits
Writes wait for a person. Runs stop at a limit.
- 6
Deploy
The agent ships with the app, in one command.
- 7
Read the logs
Every run and tool call is on record.
- 8
Test, then widen
Score it on real cases before it does more.
Step 1: Pick one job
The most common reason a first agent fails is that its job is a mood: “help sales.” Write the job as a result.
For this build, it is: given a deal, say what puts it at risk and what the rep should do next, using what the CRM already holds.
That sentence tells you what the agent reads (the deal, its risk signals, the account, the contacts and the recent activity), what it produces (a short brief) and what it must not do (change the deal). Everything later in the build follows from it. If you cannot write your job in one sentence like this, the agent is not ready to build.
Step 2: Start the app the agent will live in
On Tray Helix an agent lives inside an app. The model, instructions and tools are code in that app, and the agent ships with it. So you start with the app, and the agent is one part of it.
You do not type this code from a blank file. You describe it to your AI assistant: Claude Code, Cursor or the Claude desktop app. Every Helix project already teaches the assistant how agents and their tools are written. Setup is a one-time step: install the Helix CLI and run helix login.
Here is the first prompt for the deal coach. It builds the app and the data the agent will read.
Create a Helix app: a CRM for a sales team.
Store accounts, contacts, deals and activities. A deal has a stage,
probability, ARR, close date, owner, next step, competitor and a risk
score from 0 to 100 with the reasons behind it. Seed it with realistic
demo data: about 20 accounts, 3 contacts each, and a pipeline of open deals.
Show the pipeline as a board and each deal as a record page.
Step 3: Give the agent tools
An agent can only act through its tools, so this is the step that decides what it can do. A tool is one operation with a name, a description the model reads, and typed inputs. Keep them narrow. Seven read-only tools beat one tool that can do anything.
The deal coach gets these:
find_recordsfinds accounts, deals and contacts by name and returns their ids.read_dealreads one deal: stage, probability, ARR, close date, owner, next step, competitor.read_signalsreads a deal’s risk score and the plain-language reasons behind it.read_account,read_contactsandread_activitiesread the account, its contacts with their buying-committee roles, and the latest logged activity.read_pipelinereads every open deal.
Notice the Used by agents column. A tool belongs to the app, and any agent in the app can be given it. That is how the app’s second agent, ask-crm, reuses the same reads.
This prompt adds the tools and the agent in one go:
Add an agent called deal-coach to the CRM app.
Give it read-only tools: find_records, read_deal, read_signals,
read_account, read_contacts, read_activities and read_pipeline.
Each tool takes typed inputs, such as a deal id like o-013, and
returns only the fields it needs.
The agent must not have any tool that changes a record.
Step 4: Write the instructions
Instructions are where you say what good looks like. Write them like a brief to a new hire, not like a spell.
- The job. One sentence, the one from step 1.
- The method. “Read the deal, then its risk signals, then the account, the contacts and the last activities. Cite what you used.”
- The output. “Three lines: the biggest risk, the evidence, and the next step the rep should take this week.”
- The limits. “If a fact is not in the data, say so. Never guess a number.”
Instructions for deal-coach: You coach a sales rep on one deal. Read the
deal, its risk signals, the account, its contacts and the recent
activities. Answer in three parts: the biggest risk, the evidence from
the data, and the one next step to take this week. If the data does not
say, write "not in the CRM". Never invent a number or a contact.
Tell the agent what to refuse as clearly as what to do. Anything it reads, such as a note a customer wrote, is untrusted text. Say that in the instructions too.
Step 5: Choose the model
The agent names its model in code and can list fallbacks to try if one errors. The deal coach runs on claude-sonnet-5-5. You can call models on Amazon Bedrock through Tray, or your own provider’s models with your own key. Helix holds the key outside your code, and AI usage shows per app.
Pick the cheapest model that passes your tests in step 8, then move up only if it does not. A read-and-summarize job rarely needs the biggest one.
Step 6: Add approval and limits
This is the step that makes an agent safe to run.
Mark every tool that writes as needing approval. The run pauses before the tool runs, shows a person the tool and the exact input the model proposed, and waits. They approve or decline, and the agent picks up where it left off. Approval can depend on the input, such as refunds over $100. It is off unless you turn it on.
The deal coach has no write tools, which is why the Needs approval column in the screen above is empty. If you later add update_next_step, you would mark it for approval, and the column would show it.
Two limits come with every agent. A run stops at 25 steps or 50 tool calls by default, so a loop cannot run on. And an agent can only use the tools in the app’s code, so it cannot reach anything the app does not already reach.
Add this to the prompt when you give the agent a write:
Add a tool update_next_step that changes a deal's next step.
Mark it as needing approval, so a person sees the exact new text
before it is saved.
Step 7: Deploy it, then read the logs
Deploy from your assistant or the CLI. The agent deploys with the app in the same command. There is no separate agent service to host. Helix runs the model loop, keeps each conversation’s memory and logs every run.
Every deployment is on record, and you can restore a previous one. With deploy approvals on, a change waits for a named approver before it goes live.
Then run it. Here the app’s route POST /api/deals/o-013/coach calls the agent, and the Logs tab shows what happened.
Read a few runs before you trust the agent. Check that it called the tools you expected, in an order that makes sense, and that its answer cites what it read. The Uses AI filter on the Logs tab narrows the list to agent runs. Tray streams agent, workflow and audit logs to Splunk, Datadog or any SIEM or log tool you use.
Step 8: Test it, then widen it
An agent that worked on the case you tried has not been tested. Build a set of real cases with the answer you expect for each, run the agent on all of them, and score the results.
In Helix, the test set is a table in the app’s database. An eval function runs the agent on each case and scores the output, either with rules (“did it name the competitor on the deal?”) or with a model as judge. Run it in CI through Deploy from CI to gate the deploy. For a change that matters, deploy to a staging workspace first and use deploy approvals before it goes live. This is built from Helix parts. It is not a separate eval product.
Then widen. Give the agent one more tool, or a second job, and rerun the tests. Add one thing at a time.
What should you build after your first agent?
Once the first agent works, the same pattern covers most of the agents teams build:
- Triggered by an event. An app route, a webhook, any app event through a Tray iPaaS trigger, or a schedule can start the agent.
- Reachable where people work. A Slack or Teams message can call the agent’s route with a Helix API token, and your front end shows the answer in your brand.
- Running as the user. When an agent’s tools run through Agent Gateway, a tool’s authentication can be set to the asking user’s own credentials, so the call runs as that user when the call should.
- Measured. Each run can write its outcome, tool calls and model to the app’s database, and a dashboard app reports deflection, approval rate and cost per outcome.
Each of those is a guide with prompts you can copy on the Tray Helix Agents page. A real example of where this leads: Apollo’s IT agent, built with Tray, deflected 40% of IT tickets in its first two weeks. Read the story.
How much does it cost to build an AI agent?
You can build and run your first agent on Tray Free, $0 with no time limit. An agent has no fee of its own. Its model calls count toward its app’s usage in HCUs, on the same balance as the rest of Tray, with no per-user fees. Current rates are on the pricing page.
What mistakes do first AI agents make?
- A job that is a mood. “Help sales” has no finish line. Write the result.
- One tool that can do anything. Narrow tools are easier to approve, test and log.
- Approval nowhere, or everywhere. Put it on every write, and nowhere on reads, or approvers stop looking.
- No test set. Trying three cases by hand is not a test.
- Trusting what the agent reads. A ticket, an email or a note can contain instructions. Keep write tools behind approval.