Skip to main content
reopt Handbook
reopt Handbook
Enterprise Eve Agent Development

Core Architecture

Ch1. Eve Mental ModelCh2. Source Code AtlasCh3. Project Layout and DiscoveryCh4. Compiler and Runtime Graph

Agent Quality Design

Ch5. agent.ts, Models, CompactionCh6. Context, Skills, Dynamic CapabilitiesCh7. Tools, Approval, ConnectionsCh8. Sandbox Secure Runtime

Operational Runtime

Ch9. Channels, Auth, StreamingCh10. Subagents, Workflows, Remote AgentsCh11. Schedules, State, HooksCh12. Evals and Quality Gates

Production Operations

Ch13. Observability and DeploymentCh14. Enterprise PatternsCh15. Migration and Governance

Appendix

Official Docs CrosswalkVerification ReportUpdates
Handbook›엔터프라이즈 Eve 에이전트›Ch5. agent.ts, Models, Compaction
한국어KOEnglishEN

Ch5. agent.ts, Models, Compaction

Interpret defineAgent configuration as runtime policy for models, output schemas, compaction, and experimental flags.

Written and reviewed by Eric Han · Co-founder & CTO, reopt

Key takeaways

  • agent.ts is not just a model picker; it is runtime policy and output contract.
  • outputSchema, compaction, and modelOptions strongly affect long-session quality and cost.
  • Experimental flags and hosted-build packaging controls need owners and release gates.

Usage limits in 0.82.0: sessionUsage

Replace maxInputTokensPerSession, maxOutputTokensPerSession, and maxTokenCostUsdPerSession with limits.sessionUsage. Returning true stops the next model call.

agent/agent.ts
import { defineAgent } from "eve";

export default defineAgent({
  model: "anthropic/claude-sonnet-5.5",
  limits: {
    sessionUsage: ({ window }) =>
      window.inputTokens - window.cacheReadTokens >= 200_000 ||
      window.outputTokens >= 20_000 ||
      (window.costUsd ?? 0) >= 1.5,
  },
});
  • total is cumulative; window starts after the last approved Continue. Continue resets only the window.
  • Input includes cache usage. Subtract cacheReadTokens for new input. Optional costUsd is Gateway-reported model token cost; it excludes tools and infrastructure.
  • The call crossing a threshold may finish. These thresholds are not exact billing caps; use external spend controls as well.
  • Interactive runs pause at turn.waiting for Continue/Stop. Stop cancels the active turn and delegation tree, leaving the session resumable. Runs without human input fail with SESSION_USAGE_LIMIT_REACHED.
  • Children use their own policy or the root policy, not an allocated share of the parent's remaining budget. Test aggregation timing and cancellation exceptions.

Agent config: limits.

agent/agent.ts configures runtime behavior. In small demos it often only selects a model. In enterprise systems it decides model routing, output contracts, long-session memory behavior, and unstable feature adoption.

Basic Form

agent/agent.ts
import { defineAgent } from "eve";

export default defineAgent({
  model: "anthropic/claude-sonnet-5.5",
});

The official agent.ts docs clarify two important rules:

RuleOperational meaning
Root agent.ts can be omitted when no runtime config is neededUseful for tiny agents, but production agents should pin model/config for review.
If agent.ts is present, model is requiredDo not hide policy behind an empty defineAgent({}).

Model IDs below are routing examples. Pin the model and options you have evaluated; framework and scaffold defaults can change.

Model Routing Strategy

Model definitionExampleAdvantageCaution
Gateway model id string"anthropic/claude-opus-5.5"Vercel AI Gateway routing, central policy, OIDC flowReview Gateway model catalog and policy.
AI SDK LanguageModelanthropic("claude-opus-5.5")Direct provider controlInstall provider package and manage provider key/terms.

For enterprise teams, Gateway-routed models are usually the default because usage, fallback, cost, and policy can be centralized. Direct provider models are still valid when specific provider options or self-host constraints require them.

Model Selection Matrix

Agent typeSelection criteria
customer supportlow latency, stable instruction following, safety behavior
internal researchlong context, tool reasoning, citation discipline
code/file worktool-call stability, sandbox behavior, large context
back-office automationstructured output reliability and approval UX
eval judgeconsistency, cost, and separation from agent-under-test

The goal is not "the smartest model." The goal is the model with the lowest failure cost for the capability surface.

modelOptions

Current modelOptions accepts providerOptions and promptCache. Set portable reasoning effort with the separate reasoning field; use modelOptions.providerOptions for provider-specific controls.

Operating rules:

  • separate reasoning-heavy agents from transactional agents
  • gate model option changes like prompt changes
  • record model id and options in eval results
  • document provider-specific portability risks

outputSchema

The 0.82.0 defineAgent type has no outputSchema field. Request structured output when creating a client session, sending a turn, or sending to a child session from a workflow. The schema applies only to that turn. A tool's own outputSchema is a separate return-value validation contract.

import { Client } from "eve/client";
import { z } from "zod";

const riskSchema = z.object({
  risk: z.enum(["low", "medium", "high"]),
  requiredApprovals: z.array(z.string()),
  rationale: z.string(),
});
type RiskReview = z.infer<typeof riskSchema>;
const client = new Client({ host: "http://127.0.0.1:2000" });
const { response } = await client.sessions.create<RiskReview>({
  message: "Review the proposed operation.",
  outputSchema: riskSchema,
});
const result = await response.result();
if (!result.data) throw new Error("No structured result was produced.");
console.log(result.data.risk);

The server validates the schema. A client generic does not independently revalidate the payload, and data may be undefined when no structured result was produced. Configure route authentication before using a remote host.

Client output schema.

Compaction

The default harness summarizes older turns as the context window fills. The default threshold is 90%.

agent/agent.ts
export default defineAgent({
  model: "anthropic/claude-opus-5.5",
  compaction: {
    thresholdPercent: 0.75,
  },
});

Compaction saves context and cost, but it is also a risk surface. A bad summary can corrupt the factual base of a long session.

WorkloadRecommended policy
short FAQ/supportdefault threshold
long researchcompact earlier; persist key artifacts in files/state
coding/file workread-before-write evidence can disappear from summary
regulated decisioningexternalize important evidence
multi-subagent workstructure child results before parent aggregation

Experimental Flags

Do not copy the old experimental.codeMode or ExperimentalWorkflow exports into current configuration. Model-generated orchestration now uses the lowercase workflow() factory from eve/tools/workflow. Authored durable work uses defineWorkflowTool with a "use workflow" directive.

Check experimental.workflow world, retention, and checkpoint-batching settings against current types and a compatible World version. Keep replayed workflow bodies separate from steps that perform external effects, and configure approval independently.

Workflow tools · Agent config.

Hosted Build Packaging

build.externalDependencies keeps selected packages external in hosted output. It is packaging control, not security approval.

Review:

  • package install availability in target host
  • third-party SDK network and data behavior
  • security review for externalized dependency
  • parity between Vercel and self-host environments

Review Checklist

ItemQuestion
modelIs the routing path approved?
modelOptionsAre behavior and cost intended?
outputSchemaIs the schema on the intended turn rather than defineAgent?
compactionCan the workload tolerate summary drift?
experimentalAre unstable features scoped and evaluated?
buildAre external dependencies reviewed and deployable?

Related docs

AI Gateway Control Plane

Vercel Enterprise AI Platform · Centralize model routing, provider fallback, usage policy, and cost governance.

References

Vercel Enterprise AI Platform · Source categories for adapting the Vercel enterprise AI platform handbook.

Vercel Enterprise AI Platform

A platform handbook for designing enterprise AI products with AI SDK, AI Gateway, Workflow, Sandbox, and Queues.

Context Management

Claude Code Complete Guide · Keep Claude Code sessions accurate through memory, compaction, and concise handoffs.

Ch6. Cost and Latency Optimization

LLMOps and AgentOps in Production · Manage unit cost and response time without sacrificing quality

Ch4. Compiler and Runtime Graph

How Eve transforms source manifests into compiled manifests and runtime agent graphs.

Ch6. Context, Skills, Dynamic Capabilities

Design context, skills, dynamic tools, dynamic instructions, and dynamic skills for high-quality Eve agents.

On this page

Usage limits in 0.82.0: sessionUsageBasic FormModel Routing StrategyModel Selection MatrixmodelOptionsoutputSchemaCompactionExperimental FlagsHosted Build PackagingReview Checklist