Build an advanced agent

This recipe turns a basic agent into a production-shaped one. Each section is a self-contained add-on: it explains what the capability does for our agent and links to the reference page for the details. Apply only the add-ons you need, in any order.

Prerequisites

An agent from the Build a simple agent

The scenario

You work for a company that sells and services industrial equipment. You build Hermes, a support operations agent. A support engineer chats with Hermes, and Hermes looks up tickets, answers from the knowledge base, checks warranty status in an external CRM, drafts and sends customer emails, produces summaries and charts, and escalates to the field-service team.

The add-ons below give Hermes those abilities one at a time.

Add-on: variables in the instruction

Make the prompt adapt at runtime. Use system variables (the engineer’s name, {{currentTime}}) and a custom variable like {{region}} supplied by the caller. Instructions are versioned, so every edit is traceable and revertible.

Add-on: pre-processing script

A pre-processing script runs on every request and appends its output to the system instruction. For example, you can use it for time-critical, constantly changing data the agent should raise on its own, not data it fetches on demand (a tool’s job). For example, flag tickets about to miss their response deadline so Hermes warns the engineer up front.

const { userInfo } = payload;

if (isEngineer(userInfo)) {
    const atRisk = getTicketsNearingDeadline(userInfo);
    if (atRisk.length) {
        result =
            `This is a live update the engineer may not be aware of.\n` +
            `Inform if not already in the context:\n` +
            `${atRisk.length} ticket(s) are nearing their response deadline:\n` +
            atRisk.map((t) => `- #${t.id}: ${t.minutesLeft} min left`).join("\n");
    }
}
complete();

Add-on: tools

Tools turn Hermes from a text generator into an assistant that acts. Hermes uses:

Tool What it gives Hermes

Table tool

Read, create, and update support tickets. Restrict the read/update fields; the table’s roles are enforced at runtime and cannot be bypassed by prompt injection.

API tool

Check warranty status in the external CRM.

Email tool

Draft and send customer replies, optionally from a template.

PDF tool

Generate a PDF from a design.

Chart tool

Render the customer’s ticket history inline.

Web search tool

Pull in up-to-date external info beyond the model’s training cutoff.

Script tool

Run a device health check that aggregates live telemetry from several systems and returns a recommended fix.

A tool is only as good as its description, which tells the model when and why to use it. See AI tools.

Two orchestration settings keep a tool-heavy agent efficient:

Maximum agent steps

Caps the LLM requests per task to prevent run-away loops.

Dynamic tool selection

Sends only the tools Hermes needs each step, lowering token usage and improving tool choice.

Add-on: long conversations (compaction)

Enable compaction to summarize older messages automatically as the context window fills, instead of capping history.

See Compaction.

Give Hermes the internal knowledge base as a Vector Search Configuration. On every message, the best-matching articles are injected automatically, with no tool call needed. This is for unstructured knowledge; structured ticket data uses tools instead (below).

Add-on: external capabilities (MCP)

Let Hermes escalate through the field-service team’s existing tooling by connecting it over the Model Context Protocol, instead of building a custom integration. Import the server’s tools and select the ones Hermes may use.

Add-on: recall past conversations

Enable the Memory tool so Hermes can search the engineer’s earlier conversations with it and reuse that context.

Add-on: guardrails

Protect input and output. Order checks to fail early cheap first, expensive last:

  1. Rule (regex) on input block obvious off-topic or injection patterns.

  2. Script on input reject messages containing raw payment card numbers.

  3. AI model on output keep replies on-topic, on-brand, and free of internal data.

Also cap cost with Daily User Token Rate and enable Hide log content if conversations may contain PII.

Here’s an example of a guardrail running on the user’s input using a script.

Add-on: restrict access (roles)

Assign the support-team role so only support staff can use Hermes. This is separate from and additional to the table tool’s own role checks on the data.

Add-on: expose to other agents (A2A)

Let an orchestrator or external system call Hermes as a specialized support capability over the A2A protocol, and describe its skills in the agent card.

Add-on: tune the model behavior

Keep the response format as text (required for tool calling) and use a low temperature so support answers stay consistent. With a reasoning model, enable extended reasoning so Hermes can plan multi-step tasks.

Test and observe

Test the full flow in the Playground for example, "Pull up ticket 4821, check the customer’s warranty, and draft a reply." and watch every request, tool call, and guardrail outcome in the Agent Trace.

To integrate Hermes into an app or workflow, continue with Integrate an agent.