MessageNode API Reference¶
Bases: ABC
Base class for all message processing nodes.
agent_pool
property
writable
¶
agent_pool: AgentPool[Any] | None
Compatibility shim: returns the pool reference.
.. deprecated:: M2
Use :attr:host_context instead. The agent_pool property
will be removed in M3. host_context provides the same
infrastructure fields via an immutable :class:HostContext.
agent_type
property
¶
agent_type: str
Return the agent-type string used for persistence.
This is the persistence-domain identifier (stored in
SessionData.agent_type). It differs from :data:SourceType
which is the event-domain identifier used during streaming.
Subclasses may override this to provide a more specific type
string (e.g. "native", "acp", "claude_code").
Returns:
| Type | Description |
|---|---|
str
|
A string identifying the agent type for storage purposes. |
connection_stats
property
¶
Get stats for all active connections of this node.
host_context
property
¶
Return HostContext from the pool, if available.
message_received
class-attribute
instance-attribute
¶
message_received = Signal[ChatMessage[Any]]()
Signal emitted when node receives a message.
message_sent
class-attribute
instance-attribute
¶
message_sent = Signal[ChatMessage[Any]]()
Signal emitted when node creates a message.
task_manager
property
¶
Deprecated: backward-compat shim for the old TaskManager API.
.. deprecated::
Use :meth:spawn_task or :attr:_pending_tasks directly.
Returns:
| Type | Description |
|---|---|
_TaskManagerShim
|
A shim object that provides the old TaskManager method surface |
_TaskManagerShim
|
( |
_TaskManagerShim
|
|
_TaskManagerShim
|
|
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None
Clean up base resources.
__init__
¶
__init__(
name: str | None = None,
description: str | None = None,
display_name: str | None = None,
mcp_servers: Sequence[str | MCPServerConfig] | None = None,
agent_pool: AgentPool[Any] | None = None,
enable_logging: bool = True,
event_configs: Sequence[EventConfig] | None = None,
) -> None
Initialize message node.
__rshift__
¶
__rshift__(
other: (
MessageNode[Any, Any]
| ProcessorCallback[Any]
| Sequence[MessageNode[Any, Any] | ProcessorCallback[Any]]
),
) -> Talk[Any] | TeamTalk[Any]
Connect agent to another agent or group.
Example
agent >> other_agent # Connect to single agent agent >> (agent2 & agent3) # Connect to group agent >> "other_agent" # Connect by name (needs pool)
connect_to
¶
connect_to(
target: MessageNode[Any, Any] | ProcessorCallback[Any],
*,
queued: Literal[True],
queue_strategy: Literal["concat"]
) -> Talk[str]
connect_to(
target: MessageNode[Any, Any] | ProcessorCallback[Any],
*,
connection_type: ConnectionType = "run",
name: str | None = None,
priority: int = 0,
delay: timedelta | None = None,
queued: bool = False,
queue_strategy: QueueStrategy = "latest",
transform: AnyTransformFn[Any] | None = None,
filter_condition: AsyncFilterFn | None = None,
stop_condition: AsyncFilterFn | None = None,
exit_condition: AsyncFilterFn | None = None
) -> Talk[TResult]
connect_to(
target: Sequence[MessageNode[Any, Any] | ProcessorCallback[Any]],
*,
queued: Literal[True],
queue_strategy: Literal["concat"]
) -> TeamTalk[str]
connect_to(
target: Sequence[MessageNode[Any, TResult] | ProcessorCallback[TResult]],
*,
connection_type: ConnectionType = "run",
name: str | None = None,
priority: int = 0,
delay: timedelta | None = None,
queued: bool = False,
queue_strategy: QueueStrategy = "latest",
transform: AnyTransformFn[Any] | None = None,
filter_condition: AsyncFilterFn | None = None,
stop_condition: AsyncFilterFn | None = None,
exit_condition: AsyncFilterFn | None = None
) -> TeamTalk[TResult]
connect_to(
target: Sequence[MessageNode[Any, Any] | ProcessorCallback[Any]],
*,
connection_type: ConnectionType = "run",
name: str | None = None,
priority: int = 0,
delay: timedelta | None = None,
queued: bool = False,
queue_strategy: QueueStrategy = "latest",
transform: AnyTransformFn[Any] | None = None,
filter_condition: AsyncFilterFn | None = None,
stop_condition: AsyncFilterFn | None = None,
exit_condition: AsyncFilterFn | None = None
) -> TeamTalk
connect_to(
target: (
MessageNode[Any, Any]
| ProcessorCallback[Any]
| Sequence[MessageNode[Any, Any] | ProcessorCallback[Any]]
),
*,
connection_type: ConnectionType = "run",
name: str | None = None,
priority: int = 0,
delay: timedelta | None = None,
queued: bool = False,
queue_strategy: QueueStrategy = "latest",
transform: AnyTransformFn[Any] | None = None,
filter_condition: AsyncFilterFn | None = None,
stop_condition: AsyncFilterFn | None = None,
exit_condition: AsyncFilterFn | None = None
) -> Talk[Any] | TeamTalk
Create connection(s) to target(s).
emit_agent_event
async
¶
fire_and_forget
¶
Run a coroutine in the background without waiting for result.
The coroutine is wrapped in a try/except that logs and swallows exceptions, preventing one non-critical task failure from propagating.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coro
|
Coroutine[Any, Any, Any]
|
Coroutine to run in the background. |
required |
get_context
¶
get_context(data: Any = None, input_provider: InputProvider | None = None) -> NodeContext
Create a new context for this node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
Optional custom data to attach to the context |
None
|
input_provider
|
InputProvider | None
|
Optional input provider override |
None
|
Returns:
| Type | Description |
|---|---|
NodeContext
|
A new NodeContext instance |
get_message_history
async
¶
get_stats
abstractmethod
async
¶
Get message statistics for this node.
log_session
async
¶
log_session(
session_id: str | None = None,
initial_prompt: str | None = None,
model: str | None = None,
parent_session_id: str | None = None,
) -> None
Log conversation to storage if enabled.
Should be called at the start of run_stream() after session_id is set. For native agents, generate session_id first with uuid4(). For wrapped agents (Claude Code), set session_id from SDK session first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str | None
|
Optional session ID for the conversation. |
None
|
initial_prompt
|
str | None
|
Optional initial prompt to trigger title generation. |
None
|
model
|
str | None
|
Requested model identifier for this session. |
None
|
parent_session_id
|
str | None
|
Optional parent session ID. |
None
|
run
async
¶
Execute node with prompts via pydantic-graph single-node graph.
Builds a single-node graph and runs it to completion, wrapping the
graph run with :class:SignalEmittingGraphRun so that
message_received and message_sent signals are emitted at
step boundaries. Subclasses may override this method to provide
custom execution logic; in that case the graph-based path is
bypassed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*prompts
|
Any
|
Input prompts. |
()
|
**kwargs
|
Any
|
Additional execution arguments. |
{}
|
Returns:
| Type | Description |
|---|---|
ChatMessage[TResult]
|
The resulting ChatMessage. |
run_iter
abstractmethod
¶
run_iter(*prompts: Any, **kwargs: Any) -> AsyncIterator[ChatMessage[Any]]
Yield messages during execution.
run_message
async
¶
Run with an incoming ChatMessage (e.g., from Talk routing).
Extracts content from the message, preserves session_id, and sets parent_id to track the message chain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
ChatMessage[Any]
|
The incoming ChatMessage to process |
required |
**kwargs
|
Any
|
Additional arguments passed to run() |
{}
|
Returns:
| Type | Description |
|---|---|
ChatMessage[TResult]
|
Response ChatMessage with message chain tracked via parent_id |
run_stream
async
¶
run_stream(*prompts: Any, **kwargs: Any) -> AsyncIterator[RichAgentStreamEvent[TResult]]
Run with streaming output via pydantic-graph Graph.iter().
Uses :meth:Graph.iter to drive execution step-by-step, wrapping
the graph run with :class:SignalEmittingGraphRun so that
message_received and message_sent signals are emitted at
step boundaries. For nodes that do not override :meth:run_stream
(e.g. most agent subclasses), this yields the final result wrapped
in a :class:StreamCompleteEvent. Agent subclasses typically
override this with rich event streaming.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*prompts
|
Any
|
Input prompts. |
()
|
**kwargs
|
Any
|
Additional execution arguments. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[RichAgentStreamEvent[TResult]]
|
RichAgentStreamEvent tokens during execution. |
spawn_task
¶
Schedule a coroutine for background execution on this node.
The created task is tracked in _pending_tasks and automatically
removed when it completes. All pending tasks are awaited in
__aexit__.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coro_fn
|
Callable[..., Coroutine[Any, Any, Any]]
|
Coroutine function to call. |
required |
*args
|
Any
|
Positional arguments passed to |
()
|
Returns:
| Type | Description |
|---|---|
Task[Any]
|
The created :class: |
stop_passing_results_to
¶
Stop forwarding results to another node.
to_tool
¶
to_tool(
*, name: str | None = None, description: str | None = None, **kwargs: Any
) -> FunctionTool[TResult]
Convert node to a callable tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional tool name override |
None
|
description
|
str | None
|
Optional tool description override |
None
|
**kwargs
|
Any
|
Additional arguments for subclass customization |
{}
|
Returns:
| Type | Description |
|---|---|
FunctionTool[TResult]
|
Tool instance that can be registered |