protocol
Protocol definitions for agent interfaces in the agenty framework.
This module defines the core protocols that all agents must implement. It provides two main protocols:
- AgentIOProtocol: Defines the basic input/output interface for agents
- AgentProtocol: Extends AgentIOProtocol with additional agent-specific functionality
These protocols ensure consistent behavior across different agent implementations and enable composition of agents in pipelines.
AgentIOProtocol
Bases: Generic[AgentInputT, AgentOutputT], Protocol
Protocol defining the basic input/output interface for agents.
This protocol establishes the core contract that agents must fulfill to process input data and produce output. It supports both synchronous and asynchronous execution, and enables pipeline composition through the | operator.
Type Parameters
AgentInputT: The type of input data the agent accepts AgentOutputT: The type of output data the agent produces
Source code in agenty/protocol.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | |
input_schema
property
Get the input schema type for this agent.
Returns:
| Type | Description |
|---|---|
Type[AgentIO]
|
Type[AgentIO]: The Pydantic model class defining the expected input structure |
output_schema
property
Get the output schema type for this agent.
Returns:
| Type | Description |
|---|---|
Type[AgentIO]
|
Type[AgentIO]: The Pydantic model class defining the produced output structure |
reset()
Reset the agent's internal state.
This method should clear any cached data or state that could affect future executions.
Source code in agenty/protocol.py
83 84 85 86 87 88 89 | |
run(input_data, name=None)
async
Execute the agent asynchronously with the given input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
Optional[AgentInputT]
|
The input data to process, must conform to input_schema |
required |
name
|
Optional[str]
|
Optional name for this execution context |
None
|
Returns:
| Type | Description |
|---|---|
AgentOutputT
|
The processed output data conforming to output_schema |
Source code in agenty/protocol.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
run_sync(input_data, name=None)
Execute the agent synchronously with the given input data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
Optional[AgentInputT]
|
The input data to process, must conform to input_schema |
required |
name
|
Optional[str]
|
Optional name for this execution context |
None
|
Returns:
| Type | Description |
|---|---|
AgentOutputT
|
The processed output data conforming to output_schema |
Source code in agenty/protocol.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |
AgentProtocol
Bases: AgentIOProtocol[AgentInputT, AgentOutputT], Protocol
Protocol extending AgentIOProtocol with agent-specific functionality.
This protocol adds properties for agent identification and chat history management on top of the basic input/output operations defined in AgentIOProtocol.
Type Parameters
AgentInputT: The type of input data the agent accepts AgentOutputT: The type of output data the agent produces
Source code in agenty/protocol.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
chat_history
property
writable
Get the chat history for this agent.
Returns:
| Name | Type | Description |
|---|---|---|
ChatHistory |
ChatHistory
|
The object tracking all interactions with this agent |
name
property
Get the name of this agent instance.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The unique identifier for this agent |