Overview
TheAgent class is the central component of Tyler, providing a flexible interface for creating AI agents with tool use, delegation capabilities, and conversation management.
Creating an Agent
All Parameters
The name of your agent. This is used in the system prompt to give the agent an identity.
The LLM model to use. Supports any LiteLLM compatible model including OpenAI, Anthropic, Gemini, and more.
The agent’s purpose or system prompt. Can be a string or a Tyler Prompt object for more complex prompts.
Controls randomness in responses. Range is 0.0 to 2.0, where lower values make output more focused and deterministic.
Whether to automatically drop unsupported parameters for specific models. When True, parameters like temperature
are automatically removed for models that don’t support them (e.g., O-series models). This ensures seamless
compatibility across different model providers without requiring model-specific configuration.
List of tools available to the agent. Can include:
- Direct tool function references (callables)
- Tool module namespaces (modules like
web,files) - Built-in tool module names (strings like
"web","files") - Custom tool definitions (dicts with ‘definition’, ‘implementation’, and optional ‘attributes’ keys)
'module:tool1,tool2' format.List of sub-agents that this agent can delegate tasks to. Enables multi-agent systems and task delegation.
Maximum number of tool calls allowed per conversation turn. Prevents infinite loops in tool usage.
Custom API base URL for the model provider (e.g., for using alternative inference services).
You can also use
base_url as an alias for this parameter.Alias for
api_base. Either parameter can be used to specify a custom API endpoint.API key for the model provider. If not provided, LiteLLM will use environment variables (e.g., OPENAI_API_KEY, WANDB_API_KEY).
Use this when you need to explicitly pass an API key, such as with W&B Inference or custom providers.
Additional headers to include in API requests. Useful for authentication tokens, API keys, or tracking headers.
Enable reasoning/thinking tokens for supported models (OpenAI o1/o3, DeepSeek-R1, Claude with extended thinking).
- String:
'low','medium','high'(recommended for most use cases) - Dict: Provider-specific config (e.g.,
{'type': 'enabled', 'budget_tokens': 1024}for Anthropic)
If True, the
step() method will raise exceptions instead of returning error messages.
Used for backward compatibility and custom error handling.Supporting notes to help the agent accomplish its purpose. These are included in the system prompt
and can provide additional context or instructions.
Version identifier for the agent. Useful for tracking agent iterations and changes.
Thread store instance for managing conversation threads. If not provided, uses the default thread store.
This parameter is excluded from serialization.
File store instance for managing file attachments. If not provided, uses the default file store.
This parameter is excluded from serialization.
Custom message factory for creating standardized messages. Advanced users can provide a custom implementation
to control message formatting and structure. If not provided, uses the default factory.
This parameter is excluded from serialization (recreated on deserialization).
Custom completion handler for LLM communication. Advanced users can provide a custom implementation
to modify how the agent communicates with LLMs. If not provided, uses the default handler.
This parameter is excluded from serialization (recreated on deserialization).
Optional Pydantic model to enforce structured output from the LLM. Uses the output-tool pattern:
your Pydantic schema is registered as a special tool, and
tool_choice="required" forces the
model to call it. The validated model instance is available in AgentResult.structured_data.This approach allows regular tools to work alongside structured output. LiteLLM automatically
translates tool_choice for different providers (OpenAI, Anthropic, Gemini, Bedrock, etc.).Can be set at the agent level (default for all runs) or overridden per run() call.
See the Structured Output Guide for details.Configuration for automatic retry behavior. When enabled with structured output, the agent
will automatically retry LLM calls if validation fails, providing error feedback to help
the LLM correct its output.See RetryConfig for all options.
Default request identity passed to tools via the
ctx parameter. Primarily used for
user/org/session identity that answers “who is making this request?”Can be set at the agent level (for system agents or default identity) or per run() call
(typical for user requests). When both are provided, run-level merges with and overrides
agent-level for conflicting keys.Simple JSON mode for when you want any valid JSON without schema validation.
Pass
response_format="json" to run() to force JSON output.Creating from Config Files
Create an Agent from a YAML configuration file. Enables reusing the same configuration between CLI and Python code.
Parameters
Path to YAML config file (.yaml or .yml). If None, searches standard locations:
./tyler-chat-config.yaml(current directory)~/.tyler/chat-config.yaml(user home)/etc/tyler/chat-config.yaml(system-wide)
Override any config values. These replace (not merge) config file values using shallow dict update semantics.Examples:
tools=["web"]replaces entire tools listtemperature=0.9replaces temperature valuemcp={...}replaces entire mcp dict (not merged)
Config File Format
Advanced Config Loading
For more control over config loading, useload_config() directly:
Processing Conversations
Thego() method is the primary interface for processing conversations. It supports three output modes controlled by the stream parameter:
Non-Streaming Mode (stream=False)
With Structured Output
Get type-safe, validated responses using Pydantic models:With Tool Context (Request Identity)
Pass request-scoped identity to your tools:Event Streaming Mode (stream=True or stream=“events”)
Stream responses as high-level ExecutionEvent objects with full observability:Raw Streaming Mode (stream=“raw”)
Stream raw LiteLLM chunks in OpenAI-compatible format for direct integration:- Building OpenAI API proxies or gateways
- Direct integration with OpenAI-compatible clients
- Debugging provider-specific behavior
- Minimal latency requirements (no transformation overhead)
- ✅ Tools ARE executed (fully agentic behavior)
- ✅ Multi-turn iteration supported (continues until task complete)
- ✅ Raw chunks show tool calls via
finish_reason: "tool_calls" - ⚠️ No ExecutionEvent telemetry (only raw chunks)
- ⚠️ Silent during tool execution (brief pauses between chunk streams)
- ⚠️ Consumer handles chunk formatting (SSE serialization, etc.)
Return Values
AgentResult (Non-Streaming)
response_type, the structured_data field contains the validated Pydantic model instance.
See AgentResult for full documentation.
ExecutionEvent (Streaming)
Event Types
ITERATION_START- New iteration beginningLLM_REQUEST- Request sent to LLMLLM_RESPONSE- Complete response receivedLLM_STREAM_CHUNK- Streaming content chunkTOOL_SELECTED- Tool about to be calledTOOL_RESULT- Tool execution completedTOOL_ERROR- Tool execution failedMESSAGE_CREATED- New message addedEXECUTION_COMPLETE- All processing doneEXECUTION_ERROR- Processing failedITERATION_LIMIT- Max iterations reached
Execution Details
You can access execution information through the thread and messages:Working with Tools
Agent Delegation
Custom Configuration
Using custom API endpoints
W&B Inference configuration
Custom storage configuration
Weave Tracing and Serialization
Tyler Agent uses@weave.op() decorators for comprehensive tracing. When you initialize Weave,
all agent method calls are automatically traced and logged to your Weave dashboard.
Pydantic Serialization
Agents inherit frompydantic.BaseModel and support standard Pydantic serialization:
The following attributes are excluded from serialization and automatically recreated:
thread_store- Database connectionsfile_store- File system statemessage_factory- Message creation helpercompletion_handler- LLM communication helper
Best practices
- Clear Purpose: Define a specific, focused purpose for each agent
- Tool Selection: Only include tools the agent actually needs
- Temperature: Use lower values (0.0-0.3) for consistency, higher (0.7-1.0) for creativity
- Error Handling: Always handle potential errors in production
- Token Limits: Monitor token usage to avoid hitting limits
- Streaming: Use streaming for better user experience in interactive applications