API Reference
This section provides comprehensive documentation for Pulsar’s Python API.
Core Classes
Pulsar Engine
- class engine.executor.PulsarEngine(workflow, config=None)[source]
Bases:
objectMain workflow execution engine for Pulsar.
- Parameters:
workflow (Workflow)
config (PulsarConfig | None)
- __init__(workflow, config=None)[source]
- Parameters:
workflow (Workflow)
config (PulsarConfig | None)
- async execute(user_input='')[source]
Execute the workflow with given input.
- Parameters:
user_input (str)
- Return type:
- async execute_with_initial_state(initial_state)[source]
Execute the workflow with given initial state.
- Parameters:
- Return type:
Advanced expression evaluator for Pulsar conditional execution.
Supports template variables, string operations, membership tests, and type checking.
- exception engine.expression_evaluator.ExpressionError[source]
Bases:
ExceptionCustom exception for expression evaluation errors.
- class engine.expression_evaluator.TokenType(value)[source]
Bases:
EnumToken types for expression parsing.
- VARIABLE = 'variable'
- STRING = 'string'
- NUMBER = 'number'
- BOOLEAN = 'boolean'
- OPERATOR = 'operator'
- FUNCTION = 'function'
- PARENTHESIS = 'parenthesis'
- EOF = 'eof'
- class engine.expression_evaluator.Token(type, value, position)[source]
Bases:
objectToken representation.
- class engine.expression_evaluator.ExpressionParser(expression)[source]
Bases:
objectParser for expression language.
- Parameters:
expression (str)
- OPERATORS = {'!=': (3, <function ExpressionParser.<lambda>>), '%': (6, <function ExpressionParser.<lambda>>), '&&': (2, <function ExpressionParser.<lambda>>), '*': (6, <function ExpressionParser.<lambda>>), '+': (5, <function ExpressionParser.<lambda>>), '-': (5, <function ExpressionParser.<lambda>>), '/': (6, <function ExpressionParser.<lambda>>), '<': (4, <function ExpressionParser.<lambda>>), '<=': (4, <function ExpressionParser.<lambda>>), '==': (3, <function ExpressionParser.<lambda>>), '>': (4, <function ExpressionParser.<lambda>>), '>=': (4, <function ExpressionParser.<lambda>>), '||': (1, <function ExpressionParser.<lambda>>)}
- FUNCTIONS: Dict[str, Callable[[...], Any]] = {'contains': <function ExpressionParser.<lambda>>, 'endsWith': <function ExpressionParser.<lambda>>, 'isArray': <function ExpressionParser.<lambda>>, 'isNumber': <function ExpressionParser.<lambda>>, 'isObject': <function ExpressionParser.<lambda>>, 'isString': <function ExpressionParser.<lambda>>, 'length': <function ExpressionParser.<lambda>>, 'lower': <function ExpressionParser.<lambda>>, 'startsWith': <function ExpressionParser.<lambda>>, 'trim': <function ExpressionParser.<lambda>>, 'upper': <function ExpressionParser.<lambda>>}
- class engine.expression_evaluator.ExpressionNode[source]
Bases:
objectBase class for expression AST nodes.
- class engine.expression_evaluator.LiteralNode(value)[source]
Bases:
ExpressionNodeLiteral value node.
- Parameters:
value (Any)
- class engine.expression_evaluator.VariableNode(name)[source]
Bases:
ExpressionNodeVariable reference node.
- Parameters:
name (str)
- class engine.expression_evaluator.BinaryOpNode(left, operator, right)[source]
Bases:
ExpressionNodeBinary operation node.
- Parameters:
left (ExpressionNode)
operator (str)
right (ExpressionNode)
- left: ExpressionNode
- right: ExpressionNode
- __init__(left, operator, right)
- Parameters:
left (ExpressionNode)
operator (str)
right (ExpressionNode)
- Return type:
None
- class engine.expression_evaluator.UnaryOpNode(operator, operand)[source]
Bases:
ExpressionNodeUnary operation node.
- Parameters:
operator (str)
operand (ExpressionNode)
- operand: ExpressionNode
- __init__(operator, operand)
- Parameters:
operator (str)
operand (ExpressionNode)
- Return type:
None
- class engine.expression_evaluator.FunctionCallNode(function_name, arguments)[source]
Bases:
ExpressionNodeFunction call node.
- Parameters:
function_name (str)
arguments (List[ExpressionNode])
- arguments: List[ExpressionNode]
- __init__(function_name, arguments)
- Parameters:
function_name (str)
arguments (List[ExpressionNode])
- Return type:
None
- class engine.expression_evaluator.ArrayLiteralNode(elements)[source]
Bases:
ExpressionNodeArray literal node.
- Parameters:
elements (List[ExpressionNode])
- elements: List[ExpressionNode]
- __init__(elements)
- Parameters:
elements (List[ExpressionNode])
- Return type:
None
- class engine.expression_evaluator.ArrayAccessNode(array, index)[source]
Bases:
ExpressionNodeArray access node (e.g., arr[0]).
- Parameters:
array (ExpressionNode)
index (ExpressionNode)
- array: ExpressionNode
- index: ExpressionNode
- __init__(array, index)
- Parameters:
array (ExpressionNode)
index (ExpressionNode)
- Return type:
None
- class engine.expression_evaluator.ExpressionEvaluator(state)[source]
Bases:
objectEvaluator for parsed expressions.
- evaluate(node)[source]
Evaluate an expression node.
- Parameters:
node (ExpressionNode)
- Return type:
- engine.expression_evaluator.evaluate_expression(expression, state)[source]
Evaluate an expression with the given state.
- engine.expression_evaluator.validate_expression(expression)[source]
Validate that an expression can be parsed without errors.
- class engine.results.StepResult(*, step_name, success, output=None, error=None, execution_time, started_at, completed_at, retries=0, metadata={})[source]
Bases:
BaseModelResult of executing a single step.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class engine.results.ExecutionResult(*, workflow_name, success, final_state, step_results, total_execution_time, started_at, completed_at, error=None, execution_history=[])[source]
Bases:
BaseModelResult of executing a complete workflow.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
- step_results: List[StepResult]
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
Agent System
Base Agent
- class agents.base.AgentResult(*, output, usage={}, model, metadata={}, cost=None)[source]
Bases:
BaseModelResult from agent execution.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agents.base.BaseAgent[source]
Bases:
ABCAbstract base class for all AI agent providers.
Agent Factory
- class agents.factory.AgentFactory(config)[source]
Bases:
objectFactory for creating agent instances based on provider.
- Parameters:
config (PulsarConfig)
- __init__(config)[source]
- Parameters:
config (PulsarConfig)
Provider Agents
OpenAI Agent
- class agents.openai_agent.OpenAIAgent(config)[source]
Bases:
BaseAgentOpenAI agent implementation supporting GPT models.
- Parameters:
config (AgentConfig)
- __init__(config)[source]
- Parameters:
config (AgentConfig)
Anthropic Agent
- class agents.anthropic_agent.AnthropicAgent(config)[source]
Bases:
BaseAgentAnthropic agent implementation supporting Claude models.
- Parameters:
config (AgentConfig)
- __init__(config)[source]
- Parameters:
config (AgentConfig)
Local Agent (Ollama)
- class agents.local_agent.LocalAgent(config)[source]
Bases:
BaseAgentLocal agent implementation for Ollama and similar local models.
- Parameters:
config (AgentConfig)
- __init__(config)[source]
- Parameters:
config (AgentConfig)
Agent Configuration
- class agents.config.ProviderConfig(*, api_key=None, base_url=None, timeout=60, max_retries=3)[source]
Bases:
BaseModelConfiguration for a specific provider.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agents.config.PulsarConfig(*, openai=<factory>, anthropic=<factory>, local=<factory>)[source]
Bases:
BaseModelMain configuration for Pulsar agents.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
openai (ProviderConfig)
anthropic (ProviderConfig)
local (ProviderConfig)
- openai: ProviderConfig
- anthropic: ProviderConfig
- local: ProviderConfig
- classmethod from_dict(config_dict)[source]
Load configuration from dictionary.
- Parameters:
config_dict (Dict)
- Return type:
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
CLI Interface
Main CLI
Pulsar Compose CLI - Docker-like interface for AI workflows
CLI Configuration
- class cli.config.CLIConfig(*, default_provider='openai', history_dir='~/.pulsar/history', workflow_dir='~/.pulsar/workflows', log_level='INFO', enable_progress=True, max_history=100, plugins=<factory>)[source]
Bases:
BaseModelConfiguration for Pulsar CLI.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
History Management
- class cli.history.ExecutionHistory[source]
Bases:
objectManages execution history persistence.
- save_execution(workflow_name, result)[source]
Save execution result and return run ID.
- Parameters:
workflow_name (str)
result (ExecutionResult)
- Return type:
- get_execution_result(run_id)[source]
Get ExecutionResult object for run ID.
- Parameters:
run_id (str)
- Return type:
ExecutionResult | None
Progress Tracking
- class cli.progress.ProgressDisplay[source]
Bases:
objectHandles progress visualization for workflow execution.
- finish_execution(result)[source]
Finish progress display and show summary.
- Parameters:
result (ExecutionResult)
- show_execution_result(result)[source]
Display detailed execution results.
- Parameters:
result (ExecutionResult)
Plugin System
Input Providers
Base Provider
Console Provider
File Provider
Web Provider
Test Provider
Step Handlers
Base Handler
Agent Handler
Condition Handler
Interaction Handler
Models
- class models.state.StateManager(initial_state=None)[source]
Bases:
objectState manager for Pulsar workflow execution with advanced features.
- Parameters:
initial_state (Optional[Dict[str, Any]])
- async get(key, default=None)[source]
Get a value from the state using dot notation for nested access.
- async update_from_agent_output(step_name, output)[source]
Update state with agent output and record in execution history.
Exceptions
- class engine.executor.PulsarEngine(workflow, config=None)[source]
Bases:
objectMain workflow execution engine for Pulsar.
- Parameters:
workflow (Workflow)
config (PulsarConfig | None)
- __init__(workflow, config=None)[source]
- Parameters:
workflow (Workflow)
config (PulsarConfig | None)
- async execute(user_input='')[source]
Execute the workflow with given input.
- Parameters:
user_input (str)
- Return type:
- async execute_with_initial_state(initial_state)[source]
Execute the workflow with given initial state.
- Parameters:
- Return type:
- class agents.base.AgentResult(*, output, usage={}, model, metadata={}, cost=None)[source]
Bases:
BaseModelResult from agent execution.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
- model_config: ClassVar[ConfigDict] = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agents.base.AgentConfig(provider, api_key=None, base_url=None, timeout=60, max_retries=3)[source]
Bases:
objectConfiguration for agent providers.
- Parameters:
Pulsar Compose CLI - Docker-like interface for AI workflows
Utility Functions
Expression Evaluation
Advanced expression evaluator for Pulsar conditional execution.
Supports template variables, string operations, membership tests, and type checking.
- exception engine.expression_evaluator.ExpressionError[source]
Bases:
ExceptionCustom exception for expression evaluation errors.
- class engine.expression_evaluator.TokenType(value)[source]
Bases:
EnumToken types for expression parsing.
- VARIABLE = 'variable'
- STRING = 'string'
- NUMBER = 'number'
- BOOLEAN = 'boolean'
- OPERATOR = 'operator'
- FUNCTION = 'function'
- PARENTHESIS = 'parenthesis'
- EOF = 'eof'
- class engine.expression_evaluator.Token(type, value, position)[source]
Bases:
objectToken representation.
- class engine.expression_evaluator.ExpressionParser(expression)[source]
Bases:
objectParser for expression language.
- Parameters:
expression (str)
- OPERATORS = {'!=': (3, <function ExpressionParser.<lambda>>), '%': (6, <function ExpressionParser.<lambda>>), '&&': (2, <function ExpressionParser.<lambda>>), '*': (6, <function ExpressionParser.<lambda>>), '+': (5, <function ExpressionParser.<lambda>>), '-': (5, <function ExpressionParser.<lambda>>), '/': (6, <function ExpressionParser.<lambda>>), '<': (4, <function ExpressionParser.<lambda>>), '<=': (4, <function ExpressionParser.<lambda>>), '==': (3, <function ExpressionParser.<lambda>>), '>': (4, <function ExpressionParser.<lambda>>), '>=': (4, <function ExpressionParser.<lambda>>), '||': (1, <function ExpressionParser.<lambda>>)}
- FUNCTIONS: Dict[str, Callable[[...], Any]] = {'contains': <function ExpressionParser.<lambda>>, 'endsWith': <function ExpressionParser.<lambda>>, 'isArray': <function ExpressionParser.<lambda>>, 'isNumber': <function ExpressionParser.<lambda>>, 'isObject': <function ExpressionParser.<lambda>>, 'isString': <function ExpressionParser.<lambda>>, 'length': <function ExpressionParser.<lambda>>, 'lower': <function ExpressionParser.<lambda>>, 'startsWith': <function ExpressionParser.<lambda>>, 'trim': <function ExpressionParser.<lambda>>, 'upper': <function ExpressionParser.<lambda>>}
- class engine.expression_evaluator.ExpressionNode[source]
Bases:
objectBase class for expression AST nodes.
- class engine.expression_evaluator.LiteralNode(value)[source]
Bases:
ExpressionNodeLiteral value node.
- Parameters:
value (Any)
- class engine.expression_evaluator.VariableNode(name)[source]
Bases:
ExpressionNodeVariable reference node.
- Parameters:
name (str)
- class engine.expression_evaluator.BinaryOpNode(left, operator, right)[source]
Bases:
ExpressionNodeBinary operation node.
- Parameters:
left (ExpressionNode)
operator (str)
right (ExpressionNode)
- left: ExpressionNode
- right: ExpressionNode
- __init__(left, operator, right)
- Parameters:
left (ExpressionNode)
operator (str)
right (ExpressionNode)
- Return type:
None
- class engine.expression_evaluator.UnaryOpNode(operator, operand)[source]
Bases:
ExpressionNodeUnary operation node.
- Parameters:
operator (str)
operand (ExpressionNode)
- operand: ExpressionNode
- __init__(operator, operand)
- Parameters:
operator (str)
operand (ExpressionNode)
- Return type:
None
- class engine.expression_evaluator.FunctionCallNode(function_name, arguments)[source]
Bases:
ExpressionNodeFunction call node.
- Parameters:
function_name (str)
arguments (List[ExpressionNode])
- arguments: List[ExpressionNode]
- __init__(function_name, arguments)
- Parameters:
function_name (str)
arguments (List[ExpressionNode])
- Return type:
None
- class engine.expression_evaluator.ArrayLiteralNode(elements)[source]
Bases:
ExpressionNodeArray literal node.
- Parameters:
elements (List[ExpressionNode])
- elements: List[ExpressionNode]
- __init__(elements)
- Parameters:
elements (List[ExpressionNode])
- Return type:
None
- class engine.expression_evaluator.ArrayAccessNode(array, index)[source]
Bases:
ExpressionNodeArray access node (e.g., arr[0]).
- Parameters:
array (ExpressionNode)
index (ExpressionNode)
- array: ExpressionNode
- index: ExpressionNode
- __init__(array, index)
- Parameters:
array (ExpressionNode)
index (ExpressionNode)
- Return type:
None
Configuration Helpers
Plugin Loading
Type Definitions
from typing import Dict, List, Optional, Union, Any
from pathlib import Path
# Workflow types
WorkflowConfig = Dict[str, Any]
StepConfig = Dict[str, Any]
AgentConfig = Dict[str, Any]
# Execution types
ExecutionResult = Dict[str, Any]
StepResult = Dict[str, Any]
# Provider types
InputData = Union[str, Dict[str, Any], List[Any]]
# Template types
TemplateVars = Dict[str, Any]
RenderedTemplate = str
Constants
# Version information
__version__ = "0.1.0"
# Supported providers
SUPPORTED_PROVIDERS = ["openai", "anthropic", "ollama"]
# Default timeouts (seconds)
DEFAULT_AGENT_TIMEOUT = 30
DEFAULT_STEP_TIMEOUT = 60
# Retry configuration
DEFAULT_MAX_RETRIES = 3
DEFAULT_BACKOFF_FACTOR = 2.0
# Model defaults
DEFAULT_OPENAI_MODEL = "gpt-3.5-turbo"
DEFAULT_ANTHROPIC_MODEL = "claude-3-haiku-20240307"
DEFAULT_OLLAMA_MODEL = "llama2"
# File extensions
WORKFLOW_EXTENSIONS = [".yml", ".yaml"]
CONFIG_EXTENSIONS = [".toml", ".json", ".yaml", ".yml"]
Environment Variables
Core Configuration
- PULSAR_CONFIG_FILE
Path to configuration file. Default:
~/.pulsar/config.toml
- PULSAR_WORKFLOW_DIR
Directory containing workflow files. Default:
./workflows
- PULSAR_LOG_LEVEL
Logging level (DEBUG, INFO, WARNING, ERROR). Default:
INFO
- PULSAR_LOG_FILE
Path to log file. Default:
~/.pulsar/pulsar.log
Provider Configuration
OpenAI
- OPENAI_API_KEY
OpenAI API key (required for OpenAI agents)
- OPENAI_BASE_URL
OpenAI API base URL. Default:
https://api.openai.com/v1
- OPENAI_TIMEOUT
OpenAI API timeout in seconds. Default:
30
Anthropic
- ANTHROPIC_API_KEY
Anthropic API key (required for Anthropic agents)
- ANTHROPIC_BASE_URL
Anthropic API base URL. Default:
https://api.anthropic.com
- ANTHROPIC_TIMEOUT
Anthropic API timeout in seconds. Default:
30
Ollama
- OLLAMA_BASE_URL
Ollama API base URL. Default:
http://localhost:11434
- OLLAMA_TIMEOUT
Ollama API timeout in seconds. Default:
60
Execution Configuration
- PULSAR_MAX_CONCURRENT_STEPS
Maximum concurrent step execution. Default:
5
- PULSAR_DEFAULT_TIMEOUT
Default step timeout in seconds. Default:
300
- PULSAR_MAX_RETRIES
Default maximum retries for failed steps. Default:
3
- PULSAR_BACKOFF_FACTOR
Retry backoff factor. Default:
2.0
CLI Configuration
- PULSAR_HISTORY_SIZE
Maximum command history size. Default:
1000
- PULSAR_PROGRESS_STYLE
Progress bar style (auto, plain, rich). Default:
auto
- PULSAR_COLORS
Enable/disable colored output. Default:
true