ZytronRouter
The ZytronRouter
class is a flexible routing system designed to manage different types of zytron for task execution. It provides a unified interface to interact with various zytron types, including AgentRearrange
, MixtureOfAgents
, SpreadSheetZytron
, SequentialWorkflow
, ConcurrentWorkflow
, and finally auto
which will dynamically select the most appropriate zytron for you by analyzing your name, description, and input task. We will be continuously adding more zytron architectures as we progress with new developments.
Classes
ZytronLog
A Pydantic model for capturing log entries.
id
str
Unique identifier for the log entry.
timestamp
datetime
Time of log creation.
level
str
Log level (e.g., "info", "error").
message
str
Log message content.
zytron_type
ZytronType
Type of zytron associated with the log.
task
str
Task being performed (optional).
metadata
Dict[str, Any]
Additional metadata (optional).
ZytronRouter
Main class for routing tasks to different zytron types.
name
str
Name of the ZytronRouter instance.
description
str
Description of the ZytronRouter instance.
max_loops
int
Maximum number of loops to perform.
agents
List[Union[Agent, Callable]]
List of Agent objects or callable functions to be used in the zytron.
zytron_type
ZytronType
Type of zytron to be used.
autosave
bool
Flag to enable/disable autosave.
flow
str
The flow of the zytron.
return_json
bool
Flag to enable/disable returning the result in JSON format.
auto_generate_prompts
bool
Flag to enable/disable auto generation of prompts.
zytron
Union[AgentRearrange, MixtureOfAgents, SpreadSheetZytron, SequentialWorkflow, ConcurrentWorkflow]
Instantiated zytron object.
logs
List[ZytronLog]
List of log entries captured during operations.
Methods:
__init__
self, name: str, description: str, max_loops: int, agents: List[Union[Agent, Callable]], zytron_type: ZytronType, autosave: bool, flow: str, return_json: bool, auto_generate_prompts: bool, *args, **kwargs
Initialize the ZytronRouter.
reliability_check
self
Perform reliability checks on the ZytronRouter configuration.
_create_zytron
self, task: str = None, *args, **kwargs
Create and return the specified zytron type or automatically match the best zytron type for a given task.
_log
self, level: str, message: str, task: str = "", metadata: Dict[str, Any] = None
Create a log entry and add it to the logs list.
run
self, task: str, *args, **kwargs
Run the specified task on the selected or matched zytron.
batch_run
self, tasks: List[str], *args, **kwargs
Execute a batch of tasks on the selected or matched zytron type.
threaded_run
self, task: str, *args, **kwargs
Execute a task on the selected or matched zytron type using threading.
async_run
self, task: str, *args, **kwargs
Execute a task on the selected or matched zytron type asynchronously.
get_logs
self
Retrieve all logged entries.
concurrent_run
self, task: str, *args, **kwargs
Execute a task on the selected or matched zytron type concurrently.
concurrent_batch_run
self, tasks: List[str], *args, **kwargs
Execute a batch of tasks on the selected or matched zytron type concurrently.
Installation
To use the ZytronRouter, first install the required dependencies:
Basic Usage
Advanced Usage
Changing Zytron Types
You can create multiple ZytronRouter instances with different zytron types:
Automatic Zytron Type Selection
You can let the ZytronRouter automatically select the best zytron type for a given task:
Use Cases
AgentRearrange
Use Case: Optimizing agent order for complex multi-step tasks.
MixtureOfAgents
Use Case: Combining diverse expert agents for comprehensive analysis.
SpreadSheetZytron
Use Case: Collaborative data processing and analysis.
SequentialWorkflow
Use Case: Step-by-step document analysis and report generation.
ConcurrentWorkflow
Use Case: Parallel processing of multiple data sources.
Auto Select (Experimental)
Autonomously selects the right zytron by conducting vector search on your input task or name or description or all 3.
Advanced Features
Batch Processing
To process multiple tasks in a batch:
Threaded Execution
For non-blocking execution of a task:
Asynchronous Execution
For asynchronous task execution:
Concurrent Execution
To run a single task concurrently:
Concurrent Batch Processing
To process multiple tasks concurrently:
Best Practices
Choose the appropriate zytron type based on your task requirements.
Provide clear and specific tasks to the zytron for optimal results.
Regularly review logs to monitor performance and identify potential issues.
Use descriptive names and descriptions for your ZytronRouter and agents.
Implement proper error handling in your application code.
Consider the nature of your tasks when choosing a zytron type (e.g., use ConcurrentWorkflow for tasks that can be parallelized).
Optimize your agents' prompts and configurations for best performance within the zytron.
Utilize the automatic zytron type selection feature for tasks where the optimal zytron type is not immediately clear.
Take advantage of batch processing and concurrent execution for handling multiple tasks efficiently.
Use the reliability check feature to ensure your ZytronRouter is properly configured before running tasks.
Last updated