Agent¶
polymathera.colony.agents.base.Agent
¶
Bases: BaseModel
Base agent class representing an autonomous computational entity.
All agents have: - Unique ID and type - Lifecycle state - Optional page binding - Access to system services (VCM, LLM, blackboard)
Control flow should be driven by a reasoning LLM given sufficient context, not hardcoded. Agents adapt behavior based on current context.
Attributes:
| Name | Type | Description |
|---|---|---|
agent_id |
str
|
Unique identifier |
agent_type |
str
|
Type of agent ("specialized", "general", "service", "supervisor") |
state |
AgentState
|
Current lifecycle state |
bound_pages |
list[str]
|
Page IDs this agent is bound to (empty for unbound agents) |
created_at |
float
|
Creation timestamp |
metadata |
AgentMetadata
|
Arbitrary metadata |
state = Field(default=(AgentState.INITIALIZED))
class-attribute
instance-attribute
¶
agent_id
instance-attribute
¶
metadata = Field(default_factory=AgentMetadata)
class-attribute
instance-attribute
¶
run_step()
async
¶
Execute one step of agent logic.
This is the core method that defines agent behavior. Override in subclasses to implement specific agent logic.
This method should be idempotent and handle its own errors.
This method is @hookable, so capabilities can register BEFORE hooks to prepare for the step, AFTER hooks to post-process the step, AROUND hooks to wrap the step execution entirely, and to handle errors during execution.
NOTE: We use the repeated run_step approach instead of a single
long-running run method to facilitate easier suspension and state
management. This is necessary for distributed agents that may be
suspended and resumed across different replicas.
Source code in src/polymathera/colony/agents/base.py
2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 | |
stop(reason='completed')
async
¶
Stop agent execution.
This method is @hookable, so capabilities can register BEFORE hooks to flush memories, AFTER hooks for cleanup, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reason
|
str
|
Why the agent is stopping. Stored in |
'completed'
|
Source code in src/polymathera/colony/agents/base.py
get_blackboard(scope_id=None, backend_type='redis', enable_events=True)
async
¶
Get blackboard for reading/writing shared state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scope_id
|
str | None
|
Scope identifier (defaults to |
None
|
backend_type
|
str
|
Backend type for the blackboard (e.g., "redis") |
'redis'
|
enable_events
|
bool
|
Whether to enable events on the blackboard |
True
|
Returns:
| Type | Description |
|---|---|
EnhancedBlackboard
|
Blackboard instance |