aw.base¶
Core protocols and base classes for agentic workflows.
This module provides the foundational abstractions for building AI agents that follow the AgenticStep protocol with ReAct pattern (Reason-Act-Observe).
Classes
|
Protocol defining the interface for any agentic step in a workflow. |
|
Context for sharing state and artifacts between agentic steps. |
|
Global configuration with cascading defaults. |
|
Configuration for an AgenticStep. |
|
Protocol for tools that agents can use. |
|
Protocol for validation functions. |
- class aw.base.AgenticStep[ArtifactType](*args, **kwargs)[source]¶
Bases:
Protocol[ArtifactType]Protocol defining the interface for any agentic step in a workflow.
Each step follows the ReAct pattern:
Reason (Thought): Analyze input and context
Act (Action): Generate and execute code or use tools
Observe: Capture results and validate
Repeat or finish based on validation
Example
>>> class MyAgent: ... def execute(self, input_data, context): ... # Agent implementation ... return result, metadata
- execute(input_data, context)[source]¶
Execute the agentic step.
- Parameters:
input_data (
Any) – The input to processcontext (
MutableMapping[str,Any]) – Mutable mapping containing shared state and history
- Return type:
- Returns:
Tuple of (artifact, metadata) where artifact is the main output and metadata contains auxiliary information
- class aw.base.Context(initial_data=None)[source]¶
Bases:
MutableMapping[str,Any]Context for sharing state and artifacts between agentic steps.
Implements MutableMapping interface for dict-like behavior while providing additional functionality for managing agent state.
Example
>>> ctx = Context() >>> ctx['loading'] = {'df': df, 'info': {...}} >>> ctx['preparing'] = {'df': prepared_df}
- class aw.base.GlobalConfig(llm='gpt-4', max_retries=3, human_in_loop=False)[source]¶
Bases:
objectGlobal configuration with cascading defaults.
Provides defaults that can be overridden at step or agent level.
Example
>>> global_cfg = GlobalConfig(llm="gpt-4", max_retries=5) >>> step_cfg = global_cfg.override(llm="gpt-3.5-turbo")
- class aw.base.StepConfig(llm='gpt-4', validator=None, tools=list(), max_retries=3, human_in_loop=False)[source]¶
Bases:
objectConfiguration for an AgenticStep.
Supports both simple objects (strings, ints) and callables for maximum flexibility with dependency injection.
- llm¶
Either a model name string or a text-to-text chat function
Example
>>> config = StepConfig( ... llm="gpt-4", ... validator=lambda x: (True, {}), ... max_retries=3 ... )
- class aw.base.Tool(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for tools that agents can use.
Tools are callable objects that perform specific actions like executing code, sampling files, or calling external APIs.
Example
>>> class FileSampler: ... def __call__(self, uri): ... # Sample file logic ... return {'extension': '.csv', 'sample': '...'}
- class aw.base.Validator(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for validation functions.
Validators check if an artifact meets requirements and return both a success indicator and detailed information.
Example
>>> def is_non_empty_dataframe(df): ... success = df is not None and len(df) > 0 ... info = {'shape': df.shape if success else None} ... return success, info