翻篇收录说明
翻篇网页快照

Agent configuration (agent.ts) – eve

https://eve.dev/docs/agent-config

最近抓取:2026-12-01 23:30:51(北京时间)

最近内容变化:2026-12-01 23:30:51(北京时间)

这是最近一次有效抓取的文本快照,不含网页脚本、图片和动态交互内容。实际网页可能已更新。

访问原网页

页面简介

Configure an eve agent's model, reasoning effort, compaction, limits, and runtime behavior in agent.ts.

正文摘录

MenuAgent ConfigurationCopy for LLMView MarkdownAsk AI about this pageAn agent's optional agent.ts calls defineAgent (from eve) to configure the model and other runtime behavior. The root agent's file lives at agent/agent.ts, or in the app root with a flat layout. Declared subagents have their own agent.ts and accept the same configuration. Set the model A typical config selects a model: agent/agent.tsimport { defineAgent } from "eve"; export default defineAgent({ model: "anthropic/claude-opus-5.5", }); For a static AI Gateway model ID, make the same change with eve set model anthropic/claude-opus-5.5 from the project root or /model anthropic/claude-opus-5.5 in the local dev TUI. Omit the root agent.ts to use openai/gpt-6-luna-fast with reasoning: "high". When agent.ts is present, model is required. Every local agent.ts, root or subagent, must export the value defineAgent returns, and so must a dynamic subagent resolver that selects a local agent. The build rejects a plain object with Export defineAgent({...}) from "<path>". A gateway model ID string routes through the Vercel AI Gateway. To call a provider directly and configure the model in code, pass a model instance. eve types it as EveLanguageModel, exported from eve and eve/models, and every AI SDK language model satisfies it. With a static Gateway model, agent.ts needs no code at runtime. A dynamic model or a model instance keeps agent.ts loaded at runtime, because eve resolves it while the agent runs. See Authored module lifecycle. Use eve's helpers for direct OpenAI or Anthropic access without installing another provider package: agent/agent.tsimport { defineAgent } from "eve"; import { anthropic } from "eve/models/anthropic"; export default defineAgent({ model: anthropic(), // claude-sonnet-5 }); openai() from eve/models/openai defaults to gpt-6-luna-fast. Both helpers accept an optional native provider model ID and read OPENAI_API_KEY or ANTHROPIC_API_KEY. In local development they can also use credentials saved through /login; deployments need the API key in the server environment. For a local ChatGPT subscription, use chatgpt() from eve/models/openai and sign in with /login. It defaults to gpt-6-luna-fast and can't run in a deployment. /login can switch a static Gateway string to an eve helper and manage its import, and /model changes the selected model and settings immediately. Edit custom provider SDK calls and dynamic expressions by hand. For provider-specific configuration, install an AI SDK provider package and pass its language model. Model use is subject to the terms, data-processing commitments, retention behavior, and available controls of the selected provider and routing path. Review the AI Gateway model catalog for gateway-routed models, and review the provider's terms when you configure a direct model instance. eve fills some provider options by default. On model turns, a value you set at the same path wins unchanged; standalone compaction strips inherited caching options and forces gateway.sessionAffinity: false. OptionCallsDefault valueproviderOptions.openai.safetyIdentifier, providerOptions.anthropic.metadata.userIdOpenAI and Anthropic model and compaction callsSHA-256 fingerprint of the turn's auth.current authenticator, issuer, type, id, and subject. Unset when auth.current is null.providerOptions.gateway.sessionIdAI Gateway callsThe Agent Runs gen_ai.conversation.id, shared by every turn, delegated subagent, and compaction call in the conversation.providerOptions.openai.promptCacheKeyDirect OpenAI and chatgpt() turn callsSHA-256 hash of the session ID, unique per subagent session. Omitted on compaction calls. The safety identifier never contains the caller's raw identity fields or attributes. It follows the current caller when a later turn changes users. AI Gateway hashes session IDs longer than 256 characters. The Gateway session ID groups the conversation's generations into one session in the AI Gateway logs Sessions view. It also drives session affinity: AI Gateway tries the provider that served the previous call first so it can read its cache, which can move a provider ahead of your order. Compaction summaries always set sessionAffinity: false while keeping sessionId. To keep order on turns too, set sessionAffinity: false: agent/agent.tsimport { defineAgent } from "eve"; export default defineAgent({ model: "anthropic/claude-opus-5.5", modelOptions: { providerOptions: { gateway: { order: ["bedrock", "anthropic"], sessionAffinity: false }, }, }, }); Use a local model To test against a model on your own machine, use the AI SDK OpenAI-compatible provider. It works with any local server that implements the OpenAI Chat Completions API, such as Ollama, LM Studio, llama.cpp, or vLLM. With Ollama: pnpm add @ai-sdk/openai-compatible ollama pull gpt-oss:20b OLLAMA_CONTEXT_LENGTH=64000 ollama serve agent/agent.tsimport { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { defineAgent } from "eve"; const ollama = createOpenAICompatible({ name: "ollama", baseURL: "http://localhost:11434/v1", includeUsage: true, // report token usage while streaming }); export default defineAgent({ model: ollama("gpt-oss:20b"), modelContextWindowTokens: 64_000, }); Context window. AI Gateway has no metadata for local models, so set modelContextWindowTokens to the context length your server allocates, not the model's maximum. eve uses it to decide when to compact. Ollama allocates as little as 4K tokens by default; raise it to at least 64K for agents, as above. Tool calling. eve agents call tools on most turns, so pick a model with native tool-calling support. gpt-oss:20b, qwen3, and gemma4 are good starting points on Ollama. Usage. includeUsage: true lets token usage reach eve's session limits. Local models report no cost, so costUsd stays unset in a sessionUsage check. Other servers. Change baseURL, for example to http://localhost:1234/v1 for LM Studio. Pass apiKey for a remote OpenAI-compatible server that requires one. A deployment cannot reach a server on your machine, so use a Gateway or hosted provider model when you deploy. Choose the model dynamically To select a model from the incoming prompt with an AI SDK decision model, use auto from eve/models. model also accepts defineDynamic(fn) from eve/models or eve. The function returns the model, and a dynamic model has no compiled default. agent/agent.tsimport { defineAgent } from "eve"; import { defineDynamic } from "eve/models"; export default defineAgent({ model: defineDynamic((ctx) => ctx.session.auth.initiator?.attributes.plan === "enterprise" ? "anthropic/claude-opus-5.5" : "anthropic/claude-sonnet-5", ), }); The function returns a Gateway model ID, a model instance such as an AI SDK language model, or a selection object. See Dynamic capabilities for the context and memo rules. When it changes. eve runs the function before each ordinary model call. A memo keyed by ctx.turn?.id ?? null keeps a choice for the turn; ctx.session.id keeps it until a deployment change. Switching models can reduce prompt-cache reuse. Failures stop the turn. A thrown error or invalid selection fails the turn before the provider call. null is not a model. Missing credentials fail at request time. Serialization. Only memo results must be JSON. The function can return a live provider instance built from those results. ctx.model is unavailable during model selection. Selection object. { model, reasoning?, modelContextWindowTokens?, modelOptions? }. Omit modelContextWindowTokens to read it from the AI Gateway model catalog that eve build or eve dev recorded, without a network request. A model that catalog doesn't list fails the turn. Set modelContextWindowTokens for an unlisted, custom, or newly published model, or rebuild. Dynamic agents cannot set sibling modelContextWindowTokens or modelOptions fields; return per-model values from the function. The session.started runtime identity does not include a model ID for a dynamic agent. Each public model.started event reports the concrete model selected for that model call. Run the model on each person's credential Some agents call the model with a credential that belongs to the person using them, such as their own Vercel access token for AI Gateway. defineModel from eve/models puts a connection-style auth on a model. eve resolves the credential before each model call and passes it to create, which builds the provider model. agent/agent.tsimport { connect } from "@vercel/connect/eve"; import { createGateway } from "ai"; import { defineAgent } from "eve"; import { defineDynamic, defineModel } from "eve/models"; const ownGateway = defineModel({ id: "anthropic/claude-sonnet-5", auth: connect("vercel/myagent"), // your Vercel Connect connector for Sign in with Vercel create: ({ token }) => createGateway({ apiKey: token, teamIdOrSlug: "acme" })("anthropic/claude-sonnet-5"), }); export default defineAgent({ model: defineDynamic((ctx) => ctx.session.auth.current?.principalType === "user" ? ownGateway : "anthropic/claude-sonnet-5", ), }); A signed-in person's calls reach AI Gateway with their own Vercel access token, and teamIdOrSlug scopes the call to the acme team. Every other session uses the project's credential. FieldPurposeidIdentifies the model. eve reports it on model.started and as ctx.model.id, and looks it up in the AI Gateway model catalog for the context window. For an ID outside the catalog, set modelContextWindowTokens in the selection.authThe credential strategy: connect(...), defineInteractiveAuthorization(...), or { getToken }, as on a connection. connect(...) and defineInteractiveAuthorization(...) resolve the credential of the person who sent the turn's message, so in a shared thread each person's turns run on their own credential. As on a connection, { getToken } resolves the app's credential unless it sets principalType: "user". To vary it per caller, return a different defineModel value from defineDynamic.authKeyKeys the credential for the sign-in, th