- The type of additionalContext - Define TypeScript types for context data (user profiles, projects, etc.)
- The type of additional params - Define custom fields for your specific backend needs
- Frontend tool and state setter schemas - Define Zod schemas for tool arguments and state setter parameters
- TypeScript types for compile-time checking
- Zod schemas for runtime validation and schema factories
Additional Params Typing using E
The E generic parameter allows you to define custom fields that get passed directly to your backend.
Configurable Providers (Support Custom Fields)
Configurable providers like Mastra and Custom backends allow you to define additional parameters: TypeScript Types:Standardized Providers (Fixed APIs)
Standardized providers have fixed APIs and don’t support custom fields: TypeScript Types:Additional Context Typing using T
The T generic parameter allows you to define TypeScript types for your React state data that gets sent back in the additionalContext
field.
What your backend receives in additionalContext
Your backend receives the transformed context with Cedar system fields added and UI metadata stripped. Each context item becomes a simple object with data
and source
fields:
TypeScript Types:
Typing sendMessage
ThesendMessage
function (used by Cedar’s chat interface) and callLLM
function both accept the same typed parameters. You can pass your MyMastraRequest
type object to either:
Frontend Tool and State Setter Schema Typing
Cedar has comprehensive Zod schema support for frontend tools and state setters, providing runtime validation and automatic schema generation for agents. You can pick any schema off of theadditionalContext
object and pass it as a JSON schema to an agent’s output schema.
Frontend Tool Schema Typing
State Setter Schema Typing
Schema Benefits
Using Zod schemas for frontend tools and state setters provides:- Runtime Validation: Arguments are validated before execution
- Type Safety: Full TypeScript support with inferred types
- Agent Context: Schemas are automatically converted to JSON Schema and sent to agents
- Error Handling: Clear validation error messages
- Documentation: Schema descriptions help agents understand parameters
End-to-End Example
Here’s a simplified example showing the complete type safety pattern:Next Steps
Now that you understand request typing, learn about:- Typing Agent Responses - Type safety for agent responses and structured outputs
- Agent Backend Connection - Setting up your backend integration
- Agent Input Context - Managing context data in your Cedar application