Model Providers & Connection Setup
Relevant source files
The following files were used as context for generating this wiki page:
The Model Providers & Connection Setup system in plugsuits provides a model-agnostic interface for connecting AI agents to various Large Language Model (LLM) providers. Built upon the Vercel AI SDK, it abstracts provider-specific implementations into a unified Agent interface, allowing the core loop to interact with different models through a consistent API.
This system manages the initialization of provider clients (predominantly Anthropic), handles environment variable validation for API keys, and configures model-specific parameters such as context lengths and token limits. It serves as the foundation for both the interactive Terminal UI (TUI) and headless execution modes.
Architecture & Provider Abstraction
The architecture follows a layered approach where the harness package defines the core Agent logic, while the cea (Code Editing Agent) package implements specific provider configurations and management through the AgentManager class.
Core Agent Factory
The createAgent function in the harness acts as the primary entry point for turning a LanguageModel (from the Vercel AI SDK) into a runnable Agent. This wrapper adds support for instructions, toolsets, and experimental features like tool-call repair.
The diagram shows how various provider SDKs are unified by the createAgent factory into a consistent Agent Instance consumed by the execution loop.
Sources: packages/harness/src/agent.ts, packages/harness/README.md:25-46
AgentManager (CEA Implementation)
In the @ai-sdk-tool/cea package, the AgentManager class centralizes model selection, reasoning modes, and provider options. It is responsible for dynamically building the model instance based on current settings.
| Component | Responsibility |
|---|---|
AgentManager | Manages active modelId, provider, and reasoningMode. |
buildModel() | Constructs a wrappedModel using middleware and provider-specific options. |
getProviderOptions() | Configures provider-specific features like Anthropic's "thinking" (reasoning) budget. |
measureUsage() | Executes a minimal token probe to calculate system prompt and tool schema overhead. |
Sources: packages/cea/src/agent.ts:400-475, packages/cea/src/agent.ts:705-750
Provider Configuration & Models
The system primarily targets Anthropic as the default provider but is architected to support others via the Vercel AI SDK ecosystem.
Supported Models & Limits
Models are defined with specific token limits to guide the compaction and context management systems.
| Model ID | Name | Context Length | Max Completion Tokens |
|---|---|---|---|
claude-sonnet-4-6 | Claude Sonnet 4.6 (Latest) | 200,000 | 64,000 |
claude-opus-4-6 | Claude Opus 4.6 (Latest) | 200,000 | 32,000 |
Note: If a model is not explicitly defined, it defaults to a context length of 200,000 and an output cap of 64,000.
Sources: packages/cea/src/agent.ts:108-125, packages/cea/src/agent.ts:47-49
Connection Setup
Connections are established using environment variables. The AgentManager initializes the provider client (e.g., createAnthropic) using keys and optional base URLs for proxying.
The sequence shows the initialization flow from the CLI entrypoint through the manager to the underlying provider SDK.
Sources: packages/cea/src/agent.ts:418-435, packages/cea/src/entrypoints/main.ts:880-900
Configuration Options & Middleware
When setting up a connection, several internal and external configurations influence how the model behaves.
Reasoning Modes
The project supports "Reasoning" or "Thinking" modes, particularly for Anthropic's Claude 3.7+ models.
- Off: Standard response.
- On: Enables reasoning with a
thinkingbudget (defaulting to 10,000 tokens). - Interleaved/Preserved: Specific formatting for how reasoning tokens are handled in the stream.
Token Budgeting
The system enforces a strict OUTPUT_TOKEN_CAP (64,000 tokens) to ensure that the model does not exhaust the context window with long responses, leaving room for iterative tool loops.
Sources: packages/cea/src/agent.ts:46-47, packages/cea/src/agent.ts:133-150
Middleware Integration
Models are wrapped in a middleware chain before being passed to the harness. This allows for:
- Tool Fallback: Supporting legacy tool-calling formats (MorphXML, Hermes, Qwen) for models with weak native tool support.
- Repair Escalation: The
experimental_repairToolCallhook is used to clean up common LLM artifacts in JSON arguments, such as hashline anchors embedded in the text.
// Example of a wrapped model construction
const wrappedModel = wrapLanguageModel({
model: this.getProviderModel(this.modelId),
middleware: buildMiddlewares({
toolFallbackMode: this.toolFallbackMode,
}),
});
Sources: packages/cea/src/agent.ts:446-455, packages/cea/src/agent.ts:205-235
Conclusion
The Model Providers & Connection Setup system ensures that plugsuits remains resilient and adaptable. By abstracting the complexities of token limits, reasoning budgets, and provider-specific SDKs into the AgentManager and createAgent factory, the project allows developers to swap models seamlessly while maintaining sophisticated features like context compaction and deterministic tool execution.