Skip to Content
Foir AIAgents

Agents

An agent is an assistant you declare in your project: instructions, a model, the tools it may use, and its limits. It answers in your app or in the console, and it always works as whoever is talking to it. It reads only what that person may read and does only what they may do. An act it would not let them do without a second look waits for an approval.

You write no server for it. Your app sends a message through the generated API and follows the answer as it is written. See Use an agent in your app.

Fóir, the assistant in the console, is Foir’s own agent. Everything on this page applies to the agents you declare.

Declare an agent

Declare an agent in foir.config.ts, or create one in the console under Agents. Either way it is saved as a draft and released with the rest of your project, so production keeps running the agent you last released.

To try one before you release it, open its Runs tab in the console and choose Try it: you ask it something as yourself, it runs as it stands now with your role, and the page follows the run to its answer. Each run spends as any run of the agent does.

import { defineConfig } from '@foir/cli/configs'; export default defineConfig({ // ...your models, keys and roles agents: [ { key: 'support', name: 'Support', description: 'Answers questions about orders.', instructions: [ 'You help people with their own orders.', 'Look an order up before you answer a question about it.', 'If you cannot find the order, say so. Never guess a status.', ].join('\n'), model: { tier: 'fast' }, tools: [ { verb: 'foir_list_records', models: ['order'] }, { verb: 'foir_get_record', models: ['order'] }, { operation: 'request_refund' }, ], limits: { maxCreditsPerRun: 1, maxSteps: 8 }, }, ], });

Then push and release it:

foir push --publish

The key is the agent’s name everywhere: in the API, in a key’s grants (agents:execute:support) and in the console. It is lowercase letters, digits and _, starting with a letter, and it cannot be changed.

Tools

An agent can use four kinds of tool. You list each one it may use; it gets nothing else.

ToolDeclared asWhat it is
A Foir verb{ verb: 'foir_list_records', models: ['order'] }One of Foir’s own actions, such as listing, reading or updating records, searching, or sending a notification. models narrows a record verb to those models.
An operation{ operation: 'request_refund' }One of your project’s operations, by key.
A remote tool{ mcpServer: 'linear', mcpTool: 'create_issue' }One tool of a remote MCP server you register on the agent.
A child agent{ agent: 'researcher' }Another agent of the project, which the run can hand a task to.

Who gets which tool

A tool is offered to a run only if the person the run is for may use it. The agent’s list is the most a run can have; the caller’s role decides how much of it they get.

So one agent serves everyone. A user whose role lets them read their own orders gets foir_list_records over their own orders. A support lead whose role reads every order gets it over every order. A visitor who is not signed in gets only what your publishable key gives a visitor. Nobody gets a tool their role does not grant, whatever the agent’s list says.

Reads, writes and approvals

What a tool does decides whether it runs straight away:

  • Reads run. A Foir verb that reads, a remote tool marked readOnly, and an operation declared read-only all run without asking.
  • Drafts run. Creating or editing a record writes a draft, and adding a note is a note, so they run and nobody is surprised.
  • Everything else waits. Publishing, deleting, calling an operation that changes something, or a remote tool that is not read-only is held for an approval. The run tells the person what is waiting, and carries on once it is decided. See Approvals.

In an organization. A run started at the project reads its organizations’ records, as you do in the console. A write to a record an organization holds is sent to that organization: every Foir verb takes organization, the organization’s id, which a record’s orgId gives. The run is allowed there by the person’s own role in it. A run started from the console or by a key names its organization this way; a signed-in user of your app, or a visitor, acts where their sign-in stands.

A remote tool you trust can be marked allowed, and it then runs without an approval. A notification to the person talking to the agent runs straight away; one to anyone else waits, unless the agent sets notifyOthersUnheld.

Remote MCP servers

Register a remote server on the agent, then list the tools of it the agent may use:

mcpServers: [ { name: 'linear', url: 'https://mcp.linear.app/mcp', credential: 'perUser', tools: [ { name: 'list_issues', readOnly: true }, { name: 'create_issue' }, ], }, ],

credential says whose account the server is called with:

  • none: the server needs no sign-in.
  • project: the project’s own credential, kept as a secret and named by secretRef.
  • perUser: each person connects their own account, once. In the console that is Settings → Connected accounts; in your app it is the connectMcpServer mutation, which returns the address to send them to. A person removes their own connection there. Whoever holds agents:write also sees everyone’s connected accounts on that page, by person, and can remove any of them; the agent stops using a removed account on its next call.

A server’s address must be a public https address, and so must the sign-in and token addresses of a perUser server: the server is sent the project’s secret or a person’s token, which plain http would carry in clear. A private or local address, or plain http, is refused when the agent is pushed and again when the server is called.

Child agents

An agent can hand part of a task to another agent of the same project by listing it as a tool. The child runs as the same caller, with that caller’s permissions, and spends from the same run’s budget. limits.maxDepth says how deep children may nest, up to 3; it is 0 unless you set it, so an agent calls no child until you allow one.

The model

An agent runs on one of Foir’s tiers, paid for in AI credits:

TierFor
fastQuick answers and lookups. The cheapest.
balancedMost work that reads and writes across several steps.
bestThe hardest tasks. The most expensive.

Or it runs on your own provider key, and costs no credits:

model: { provider: 'anthropic', model: 'claude-sonnet-5', secretRef: 'ANTHROPIC_KEY', monthlyCapUsd: 200, },

The key is a project secret named by secretRef. Spend on it is recorded against the agent and stops at monthlyCapUsd. An agent on your own key never falls back to Foir’s models: if the key is refused or the cap is reached, the run says so.

Limits

LimitWhat it boundsWhen unset
maxCreditsPerRunThe most one run may spend, its children included. A run that would pass it is refused before its next step.2 credits
maxStepsModel turns in one run, its children’s included.12 (at most 64)
maxMessageCharsThe longest message a caller may send.8,000 (2,000 for a visitor)
maxTurnsMessages one caller may send in one conversation.50 (20 for a visitor)
maxDepthHow deep child agents may nest.0 (at most 3)
quotasRequests per caller in a window, written as an operation’s quotas.none

A run does not stop mid-thought at either of the first two. Its last step, or the step after which another like it would leave too little to write an answer, calls no tool: the agent answers from what it has found so far, or says it did not find the answer.

retentionDays is how long a conversation is kept after its last message: 30 days unless you set it.

Earlier turns

Each message in a conversation reaches the model with what came before it. history says how much:

history: { keep: 'answers' },
keepWhat the model is given of each earlier turn
everythingThe whole turn: every tool call, its result and the model’s reasoning. The default.
answersThe question and the answer, without the tool calls or their results.
recentThe last turns in full (1 to 50), and those before them as answers.
compactOnce the earlier turns pass about afterTokens tokens (2,000 to 200,000), a summary of all but the last recentTurns, in their place.

The current turn always goes in full. Keep everything where a later turn acts on what an earlier one found, such as a record’s id: an assistant that edits content needs it. An agent that answers visitors from a few pages does not, and answers keeps each follow-up close to the cost of the first question.

A compacting agent’s summary is written on Foir’s fast tier (on your own key, on your own model), charged to the run that writes it, and kept with the conversation. The turns after it are summarised with it once they pass afterTokens in turn, so a long conversation is summarised now and then, not on every message. If a summary cannot be written, the turns it would cover go as their answers.

A run is priced before each call on what is sent, so a shorter history also stays further from maxCreditsPerRun.

Agents anyone can talk to

An agent your publishable key lets a visitor run is public. A public run is held to more than the agent’s limits:

  • A safety check. Every message is checked before the agent sees it. A message the check flags is refused, and so is one it could not check: a public agent never runs unchecked.

  • Your own rules. refusalRules refuse a message on your terms, with the answer you write:

    refusalRules: [ { key: 'no_links', when: { type: 'condition', left: { type: 'context', path: 'message.text' }, operator: 'contains', right: { type: 'literal', value: 'http', valueType: 'string' }, }, message: 'Please ask without links.', }, ],

    A rule is a rule expression. It reads message.text, message.length and caller.signedIn as context operands, and the first rule that matches refuses the message with its message.

  • Credits are checked first. A public run starts only when the project can pay for it. If the balance cannot be read, it does not start.

A refused message is answered in the conversation and costs nothing.

The project brief

The project brief is what every agent in the project is told first, before its own instructions: what the business is, how it speaks, and what an agent must always or never do. Fóir reads it too.

brief: { text: 'We sell refurbished cameras. Be plain and friendly. Never promise a delivery date.', modelRules: { order: 'An order is read by its number, never by the name on it.', }, },

modelRules adds a rule for a particular model, by its key; every agent is given them after the brief’s text. The brief is released with the project, and edited in the console under Settings → Project brief.

Who may do what

PermissionLets a person
agents:readSee the project’s agents, and every run of them with its trace.
agents:writeCreate, change and delete agents.
agents:executeTalk to agents. agents:execute:support names one.
brief:read, brief:writeRead and edit the project brief.
approvals:writeDecide an act held for the team, with the permission the act itself needs.

Anyone may read their own conversations and runs, and decide an act held for them.

A remote tool is given by name too: agenttools:execute:support.linear.create_issue is one tool of one server on one agent, and agenttools:execute is every one. In the console’s role editor, Talk to one agent lists the project’s agents with the remote tools each may use, so a role can give the support agent and keep the rest to the team.

Last updated on