Maniac Docs
Agents

Agent Spec

Every field on the Agent interface — model, tools, middleware, budgets, reasoning, and structured output.

An Agent (alias AgentSpec) is the declarative configuration the runner executes. Pass it to runAgent, runAgentStream, or register it on Maniac.

Required fields

import type { Agent } from "@maniac-ai/agents";

const spec: Agent = {
  id: "researcher",
  instructions: "Be thorough and cite sources.",
  model: new OpenAICompatibleModel({ slug: "gpt-4o" })
};
FieldTypeDescription
idstringStable agent identifier for tracing and memory namespaces
instructionsstring | InstructionsBuilderSystem prompt, or a function of RequestContext
modelModelProvider adapter implementing infer and stream

Tools and toolsets

const spec: Agent = {
  id: "support",
  instructions: "...",
  model,
  tools: [lookupOrder],           // inline Tool definitions
  toolsets: [mcpFilesystem]       // BaseToolset / MCPToolset instances
};

See Defining tools and Builtin tools.

Depth and delegation

FieldDefaultDescription
max_depth1Maximum nested sub-agent depth when toolsets call asDelegated()

Budget

budget: {
  max_iterations: 32,      // LM loop iterations (default 32)
  max_tokens: 50_000,      // cumulative prompt + completion tokens
  max_cost_usd: 1.0,       // cumulative USD when provider reports cost
  max_wall_seconds: 120    // wall-clock ceiling
}

Omit fields to disable that limit. See Running agents — budgets.

Middleware and guardrails

FieldPurpose
lm_middlewareTransform or log InferenceRequest / InferenceResponse
tool_middlewareWrap tool invocation
lm_guardrailsBlock, rewrite, or require approval on LM output
tool_guardrailsBlock, rewrite, or require approval on tool calls

See Middleware and Permissions.

Step hooks

FieldPurpose
step_hooksbeforeStep, shouldStop, afterStep, beforeFinalize hooks
prepare_stepSugar for a beforeStep hook that rewrites the next request
stop_whenSugar for a custom termination predicate

Hooks compose left-to-right in registration order.

Structured output

import { z } from "zod";

const OutputSchema = z.object({
  answer: z.string(),
  count: z.number().int()
});

const spec: Agent = {
  id: "assistant",
  instructions: "Respond with JSON matching the schema.",
  model,
  output_model: OutputSchema,
  output_repair_attempts: 1  // default 1 when output_model is set
};

Validated value lands on AgentResult.output. See Running agents — structured output.

Reasoning

reasoning: { effort: "high" }  // "minimal" | "low" | "medium" | "high"
// or
reasoning: { max_tokens: 10_000 }  // Anthropic thinking.budget_tokens

Applied to every LM call unless a prepare_step hook overrides request.reasoning. See Streaming and reasoning.

Other fields

FieldDescription
replPython REPL config (PythonSandboxClient)
memoryPer-agent memory override
observational_memoryPer-agent observation config
policyPermission policy override
backgroundPer-agent background-task eligibility
plans_enabledAuto-inject set_plan tool (default false)

AgentSpec is a deprecated alias kept for backwards compatibility.

On this page