Workflow Configuration Documentation¶
Comprehensive documentation for workflow configurations in Bast AI Agno.
Reference: Agno Workflow Documentation
Overview¶
Agno Workflows enable deterministic, controlled agentic flows by orchestrating agents, teams, and functions through a series of defined steps. This provides structured automation with predictable execution patterns, making them ideal for production systems that require reliable, repeatable processes.
Quick Start¶
Basic Usage¶
from bast_ai_agno.bp import AgnoWorkflowFactory
from bast_ai_agno.dto.workflows import simple_workflow_config
# Create factory
factory = AgnoWorkflowFactory(catname="your_catname")
# Create workflow from config
workflow = factory.create_workflow_from_json({
"name": "my_workflow",
**simple_workflow_config
})
# Run workflow
response = workflow.run(
input="What are the main benefits of using AI in healthcare?",
stream=False
)
print(response.content)
Running a Workflow¶
Based on Agno Workflow Documentation:
from bast_ai_agno.bp import AgnoWorkflowFactory
from bast_ai_agno.dto.workflows import simple_workflow_config
from agno.run.workflow import WorkflowRunOutput
factory = AgnoWorkflowFactory(catname="your_catname")
# Create workflow
workflow = factory.create_workflow_from_json({
"name": "content_workflow",
**simple_workflow_config
})
# Run workflow synchronously
response: WorkflowRunOutput = workflow.run(
input="AI trends in 2024",
stream=False
)
# Access response content
print(response.content)
Async Execution¶
import asyncio
async def main():
factory = AgnoWorkflowFactory(catname="your_catname")
workflow = factory.create_workflow_from_json({
"name": "async_workflow",
**simple_workflow_config
})
# Run workflow asynchronously
response: WorkflowRunOutput = await workflow.arun(
input="Recent breakthroughs in quantum computing"
)
print(response.content)
if __name__ == "__main__":
asyncio.run(main())
Module Structure¶
Business Process Modules¶
bp/agno_workflows.py-AgnoWorkflowFactoryclass for creating workflows from configuration/templatesbp/mongodb_resources.py- MongoDB storage resources with separate workflow database
Configuration Modules¶
dto/workflows/simple_workflow_config.py- Simple workflow configuration templatedto/workflows/__init__.py- Workflow configuration exports
Integration Tests¶
integration/workflows/simple_workflow_check.py- Integration tests for workflows
Workflow Factory¶
AgnoWorkflowFactory¶
The AgnoWorkflowFactory class provides methods to create workflows from JSON configurations and templates.
Methods¶
create_workflow_from_json(workflow_json)- Creates a workflow from JSON configuration
- Handles nested config structures
-
Returns a
Workflowobject -
create_workflow(name, steps, db, config_raw) - Creates a workflow with direct parameters
- Supports steps as agents, teams, or functions
-
Automatically configures workflow storage
-
check_and_define_step(step_data) - Analyzes step data and creates appropriate step type
- Supports agents, teams, and functions
-
Handles nested configurations
-
create_workflow_from_template(template_name, **kwargs) - Creates workflow from predefined template (ready for extension)
- Template system for common workflow patterns
Example Usage¶
from bast_ai_agno.bp import AgnoWorkflowFactory
factory = AgnoWorkflowFactory(catname="your_catname")
# Create from JSON
workflow = factory.create_workflow_from_json({
"name": "my_workflow",
"steps": [
{"agent": {"name": "researcher", "instructions": ["Research topics"]}},
{"agent": {"name": "writer", "instructions": ["Write content"]}}
]
})
# Create directly
workflow = factory.create_workflow(
name="my_workflow",
steps=[agent1, team1, custom_function]
)
Workflow Storage¶
Separate MongoDB Database¶
Workflows use a separate MongoDB database dedicated to workflow storage, distinct from agent storage. This ensures workflow execution data is stored independently, facilitating better organization, scalability, and maintenance.
Database Structure¶
- Database Name:
{prefix}_agno_workflow - Collections:
{workflow_name}_sessions- Workflow session data{workflow_name}_memory- Workflow memory{workflow_name}_metrics- Workflow metrics{workflow_name}_eval- Evaluation data{workflow_name}_kb- Knowledge base data
Usage¶
from bast_ai_agno.bp import AgnoMongoDBResources
resources = AgnoMongoDBResources(catname="your_catname")
# Get workflow storage
workflow_storage = resources.get_workflow_storage("my_workflow")
# Use in workflow creation
workflow = factory.create_workflow(
name="my_workflow",
db=workflow_storage,
steps=[...]
)
Workflow Configurations¶
Simple Workflow Configuration¶
The simple_workflow_config provides a basic workflow template with two sequential agents:
from bast_ai_agno.dto.workflows import simple_workflow_config
# Simple workflow with researcher and writer agents
simple_workflow_config = {
"steps": [
{
"agent": {
"name": "researcher",
**basic_agent_config,
"instructions": [
"You are a research assistant.",
"Gather information and provide comprehensive summaries."
],
"model": "gpt-4o-mini",
}
},
{
"agent": {
"name": "writer",
**basic_agent_config,
"instructions": [
"You are a content writer.",
"Create well-structured content based on the research provided."
],
"model": "gpt-4o-mini",
}
}
]
}
Custom Workflow Configuration¶
You can create custom workflow configurations:
from bast_ai_agno.dto.agents.agent_configs import basic_agent_config
custom_workflow_config = {
"steps": [
# Step 1: Research agent
{
"agent": {
"name": "researcher",
**basic_agent_config,
"instructions": ["Research the topic"],
"model": "gpt-4o",
}
},
# Step 2: Analysis team
{
"team": {
"name": "analysis_team",
"members": [
{"name": "analyst1"},
{"name": "analyst2"}
],
"model": "gpt-4o",
}
},
# Step 3: Custom function
my_custom_processing_function
]
}
Workflow Steps¶
Workflow steps can be:
- Agents - Individual AI executors
- Teams - Coordinated groups of agents
- Functions - Custom Python functions (async functions)
Step Definition¶
Steps can be defined in multiple ways:
As Dictionary¶
As Object¶
from bast_ai_agno.bp import AgnoAgentFactory
agent_factory = AgnoAgentFactory(catname="your_catname")
agent = agent_factory.create_openai_chat_agent(
name="my_agent",
config_raw=basic_agent_config
)
# Use directly in workflow
workflow = factory.create_workflow(
name="my_workflow",
steps=[agent] # Use agent object directly
)
As Function¶
async def custom_processing(step_input):
# Process input
result = await some_processing(step_input.previous_step_content)
return result
# Use in workflow
workflow = factory.create_workflow(
name="my_workflow",
steps=[custom_processing] # Use function directly
)
Integration Tests¶
Running Workflow Tests¶
Test Coverage¶
The integration test (simple_workflow_check.py) covers:
- Factory Initialization - Verifies factory can be created
- Workflow Creation from Config - Tests JSON-based workflow creation
- Direct Workflow Creation - Tests direct workflow creation
- Step Definition - Validates workflow steps are correctly defined
- Storage Configuration - Verifies workflow database is configured
- Workflow Execution - Tests actual workflow execution with
workflow.run() - Error Handling - Tests error handling with invalid inputs
DTO Folder Reorganization¶
The dto folder has been reorganized for better structure:
New Structure¶
dto/
├── agents/ # All agent configurations
│ ├── agent_configs.py
│ ├── core_agent_configs.py
│ ├── memory_configs.py
│ ├── knowledge_configs.py
│ └── ...
├── utils/ # All utility functions
│ ├── agent_config_utils.py
│ ├── agent_tool_utils.py
│ ├── agent_reasoning_utils.py
│ └── ...
├── workflows/ # Workflow configurations
│ ├── simple_workflow_config.py
│ └── __init__.py
└── output/ # Output schemas
└── early_exit_output.py
Backward Compatibility¶
All old import paths still work:
# Old imports still work
from bast_ai_agno.dto.agent_configs import basic_agent_config
from bast_ai_agno.dto.agent_config_utils import add_tools_to_config
from bast_ai_agno.dto.core_agent_configs import greeting_agent_config
# New imports (preferred)
from bast_ai_agno.dto.agents.agent_configs import basic_agent_config
from bast_ai_agno.dto.utils.agent_config_utils import add_tools_to_config
from bast_ai_agno.dto.agents.core_agent_configs import greeting_agent_config
Examples¶
Example 1: Simple Research Workflow¶
from bast_ai_agno.bp import AgnoWorkflowFactory
from bast_ai_agno.dto.workflows import simple_workflow_config
factory = AgnoWorkflowFactory(catname="your_catname")
workflow = factory.create_workflow_from_json({
"name": "research_workflow",
**simple_workflow_config
})
response = workflow.run(
input="What are the latest trends in AI?",
stream=False
)
print(response.content)
Example 2: Custom Workflow with Teams¶
from bast_ai_agno.bp import AgnoWorkflowFactory, AgnoTeamFactory
workflow_factory = AgnoWorkflowFactory(catname="your_catname")
team_factory = AgnoTeamFactory(catname="your_catname")
# Create team
research_team = team_factory.create_team_from_json({
"name": "research_team",
"members": [
{"name": "researcher1"},
{"name": "researcher2"}
]
})
# Create workflow with team
workflow = workflow_factory.create_workflow(
name="team_workflow",
steps=[research_team]
)
response = workflow.run(input="Research quantum computing")
Example 3: Workflow with Custom Function¶
async def preprocess_input(step_input):
"""Preprocess input before agent processing"""
processed = step_input.input.lower().strip()
return {"content": processed}
async def postprocess_output(step_input):
"""Postprocess output after agent processing"""
output = step_input.previous_step_content
return {"content": f"[PROCESSED] {output}"}
workflow = factory.create_workflow(
name="processing_workflow",
steps=[
preprocess_input,
{"agent": {"name": "processor", "instructions": ["Process the input"]}},
postprocess_output
]
)
Best Practices¶
- Reuse Workflows - Create workflows once and reuse them (similar to agents)
- Use Configurations - Leverage workflow configurations for consistency
- Separate Storage - Use separate workflow databases for better organization
- Error Handling - Wrap workflow execution in try-except blocks
- Logging - Enable workflow event storage for debugging and auditing
- Testing - Use integration tests to verify workflow functionality
Early Exit Workflows¶
For workflows with conditional routing based on early exit decisions, see:
- EARLY_EXIT_WORKFLOWS.md - Complete guide for early exit workflows with conditional routing
- Includes patterns for greeting detection, conversation ending, and main workflow routing
- Covers common issues and solutions (Step objects vs functions, input passing, etc.)
Quick Example¶
from bast_ai_agno.dto.workflows import route_by_early_exit_decision
from bast_ai_agno.dto.workflows.conditional_agent_routing import (
make_conditional_greeting_wrapper,
make_conditional_end_conversation_wrapper,
make_conditional_main_workflow_wrapper,
)
# Create conditional wrappers
conditional_greeting = make_conditional_greeting_wrapper(greeting_agent)
conditional_end_conversation = make_conditional_end_conversation_wrapper(end_conversation_agent)
conditional_main_workflow = make_conditional_main_workflow_wrapper(main_workflow_agent)
# Create workflow with conditional routing
workflow = factory.create_workflow(
name="early_exit_workflow",
steps=[
early_exit_agent,
route_by_early_exit_decision,
conditional_greeting,
conditional_end_conversation,
conditional_main_workflow,
]
)
Important Notes:
- Use functions directly, not Step objects (factory doesn't recognize Step objects)
- Pass original input through routing decision for conditional wrappers
- Reuse workflows and agents for performance (see WORKFLOW_PERFORMANCE_OPTIMIZATION.md)
External Resources¶
Getting Help¶
- Check the Agno Workflow Documentation
- Review integration tests in
integration/workflows/ - See workflow configurations in
dto/workflows/ - Refer to
bp/agno_workflows.pyfor factory implementation - For early exit workflows, see EARLY_EXIT_WORKFLOWS.md