Overview
CopilotRuntime is the central runtime object that manages agents, transcription services, middleware, and agent runners on the server side. It’s passed to all request handlers and provides the execution environment for agents.
Constructor
Parameters
Map of available agents indexed by agent ID. Can be a Promise that resolves to the agent map (for lazy loading).
The runner implementation to use for executing agents. Defaults to
InMemoryAgentRunner.Optional service for audio transcription (for voice input features).
Optional middleware function or webhook URL called before processing requests. Can modify requests or reject them.
Optional middleware function or webhook URL called after processing requests. Useful for logging, analytics, etc.
Auto-apply A2UI middleware to agents at runtime for computer use capabilities.
Auto-apply MCP (Model Context Protocol) Apps middleware to agents.
Properties
agents
runner
transcriptionService
beforeRequestMiddleware
afterRequestMiddleware
a2ui
mcpApps
Usage Examples
Basic Runtime
With Custom Runner
With Middleware
With Transcription Service
With MCP Apps
Lazy Loading Agents
Multiple Agents
Middleware Types
BeforeRequestMiddleware
- Webhook URL: POST request sent to URL with request details
- Function: Can modify request or return Response to short-circuit
- Return
undefined: Continue with original request - Return
Request: Use modified request - Return
Response: Short-circuit and return response
AfterRequestMiddleware
- Webhook URL: POST request sent to URL with response details
- Function: Called after response is generated (fire-and-forget)
- Note: Cannot modify the response
Endpoint Integration
Use the runtime with endpoint adapters:See Also
- AgentRunner - Agent execution interface
- Express Adapter - Express integration
- Hono Adapter - Hono integration
- BuiltInAgent - Built-in agent implementation
