Skip to content

Instructions ​

Instructions define how an agent should behave. Use them for durable policy, role, tone, and workflow rules that apply to every run.

Add stable instructions ​

ts
const agent = new AgentBuilder('support', model)
  .instructions([
    'Answer from verified support information.',
    'Use tools before making account-specific claims.',
    'Escalate billing, legal, or security uncertainty.',
  ].join('\n'))
  .build()

Good instructions describe repeatable behavior. They should not contain the current user's permissions, tenant ID, database IDs, or other request-specific facts.

Compose instruction blocks ​

Multiple .instructions(...) calls append blocks in order; they do not replace earlier instructions.

ts
const agent = new AgentBuilder('research', model)
  .instructions(baseAgentRules)
  .instructions(researchWorkflowRules)
  .skills(researchSkills)
  .build()

Anvia combines normal instruction blocks first, followed by skill instructions. Keep the order intentional and remove contradictory rules.

Choose the right boundary ​

InformationPut it in
Durable behavior and policyInstructions
Facts the model should useContext
User or tenant identitySession and runner state
Product permissionsTool handlers and services
Trace correlation.withTrace(...)

If one request needs fundamentally different behavior, create a different agent or scoped factory instead of appending conflicting instructions at runtime.

Keep enforcement in code ​

Instructions can tell a model when to use a tool, but they cannot enforce safety. Every side-effect tool must still validate the user, tenant, input, permissions, and approval state.

Built for Anvia.