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

AgenticStep(*args, **kwargs)

Protocol defining the interface for any agentic step in a workflow.

Context([initial_data])

Context for sharing state and artifacts between agentic steps.

GlobalConfig([llm, max_retries, human_in_loop])

Global configuration with cascading defaults.

StepConfig([llm, validator, tools, ...])

Configuration for an AgenticStep.

Tool(*args, **kwargs)

Protocol for tools that agents can use.

Validator(*args, **kwargs)

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:

  1. Reason (Thought): Analyze input and context

  2. Act (Action): Generate and execute code or use tools

  3. Observe: Capture results and validate

  4. 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 process

  • context (MutableMapping[str, Any]) – Mutable mapping containing shared state and history

Return type:

tuple[ArtifactType, dict[str, Any]]

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}
property history: list[tuple[str, Any]]

Access the history of all context updates.

snapshot()[source]

Create a snapshot of current context state.

Return type:

dict[str, Any]

Returns:

A dict copy of current context data

class aw.base.GlobalConfig(llm='gpt-4', max_retries=3, human_in_loop=False)[source]

Bases: object

Global 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")
override(**kwargs)[source]

Create a StepConfig with overridden values.

Parameters:

**kwargs – Values to override from global defaults

Return type:

StepConfig

Returns:

A new StepConfig with merged configuration

class aw.base.StepConfig(llm='gpt-4', validator=None, tools=list(), max_retries=3, human_in_loop=False)[source]

Bases: object

Configuration 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

Type:

Union[str, Callable[[str], str]]

validator

Validation callable or schema object

Type:

Union[Callable, Any]

tools

List of callable tools available to the agent

Type:

list[Callable]

max_retries

Maximum number of retry attempts

Type:

int

human_in_loop

Whether to require human approval/intervention

Type:

bool

Example

>>> config = StepConfig(
...     llm="gpt-4",
...     validator=lambda x: (True, {}),
...     max_retries=3
... )
resolve_llm()[source]

Resolve llm to a callable function.

Return type:

Callable[[str], str]

Returns:

A callable that takes a prompt string and returns a response string

resolve_validator()[source]

Resolve validator to a callable.

Return type:

Validator

Returns:

A callable that validates artifacts

class aw.base.Tool(*args, **kwargs)[source]

Bases: Protocol

Protocol 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: Protocol

Protocol 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