Functions
ok()
Create a success result.
Returns:
OkResult
Example:
err()
Create an error result.
Returns:
ErrResult
Example:
Types
AgentResult
Union type for handler return annotations:OkResult
Success result dataclass:data field serializes to JSON over NATS. Complex objects should be dicts or lists.
ErrResult
Error result dataclass:error message is passed through to the host and displayed to the user.
AgentExtras
Optional metadata for success results:reasoning- Explanation of agent decisions, shown in UI for transparencyartifact_refs- References to created platform artifactsoutline_refs- Structured entries for conversation outline
ArtifactRef
Reference to a platform artifact:/api/artifacts endpoint.
OutlineRef
Structured reference for conversation outline:Tagged Union Pattern
OkResult and ErrResult are distinct types. It is impossible to:
- Return success data with an error message
- Return error data with success extras
- Confuse the two in type checking
Serialisation
Results serialize to a JSON envelope over NATS:AgentExtras is serialized separately and merged by the host.
Best Practices
- Return structured data - Dicts with clear field names, not raw strings
- Provide reasoning - Helps users understand agent decisions
- Create artifacts for large outputs - Persist reports, analyses, generated code
- Use outline_refs for scannable results - Helps navigate complex outputs
- Handle errors early - Validate
ctx.env, check capabilities, returnerr()with clear messages
Common Error Messages
See Also
How to Stream Progress
Real-time updates during execution

