praval.composition
Composition utilities for decorator-based agents.
This module provides utilities for composing and orchestrating agents decorated with the @agent decorator.
Functions
|
Compose agents into a pipeline that processes data sequentially. |
|
Decorator for conditional agent execution. |
|
Convenience function to start multiple agents with initial data. |
|
Decorator to throttle agent execution. |
Classes
|
Context manager for coordinated agent sessions. |
- praval.composition.agent_pipeline(*agents, channel='pipeline')[source]
Compose agents into a pipeline that processes data sequentially.
- Parameters:
- Return type:
- Returns:
Function that triggers the pipeline with initial data
Example
pipeline = agent_pipeline(explorer, analyzer, reporter) pipeline({“task”: “analyze sentiment”})
- praval.composition.conditional_agent(condition_func)[source]
Decorator for conditional agent execution.
Example
@conditional_agent(lambda spore: spore.knowledge.get(“priority”) == “high”) @agent(“urgent_processor”) def process_urgent(spore):
return {“processed”: True}
- praval.composition.throttled_agent(delay_seconds)[source]
Decorator to throttle agent execution.
- Parameters:
delay_seconds (
float) – Minimum seconds between executions
Example
@throttled_agent(2.0) # Max once every 2 seconds @agent(“slow_processor”) def process_slowly(spore):
return {“processed”: True}
- class praval.composition.AgentSession(session_name)[source]
Bases:
objectContext manager for coordinated agent sessions.
Example
- with AgentSession(“knowledge_mining”) as session:
session.add_agents(explorer, analyzer, curator) session.broadcast({“task”: “mine concepts about AI”})
- Parameters:
session_name (str)
- add_agent(agent_func)[source]
Add an agent to this session.
- Return type:
- Parameters:
agent_func (Callable)
- add_agents(*agent_funcs)[source]
Add multiple agents to this session.
- Return type:
- Parameters:
agent_funcs (Callable)
- praval.composition.start_agents(*agent_funcs, initial_data=None, channel='startup')[source]
Convenience function to start multiple agents with initial data.
- Parameters:
- Return type:
- Returns:
Spore ID of startup broadcast
Example
- start_agents(explorer, analyzer, curator,
initial_data={“task”: “analyze market trends”})