pipeline
Pipeline
Bases: Generic[AgentInputT, AgentOutputT]
A pipeline for chaining multiple agents together for sequential processing.
The Pipeline class enables the creation of agent chains where data flows from one agent to the next. Each agent in the pipeline must have compatible input/output schemas, where each agent's output schema matches the next agent's input schema.
Type Parameters
AgentInputT: The type of input the pipeline accepts (e.g., str, dict, List[User]) AgentOutputT: The type of output the pipeline produces (e.g., List[str], Report)
Attributes:
| Name | Type | Description |
|---|---|---|
input_schema |
Type[AgentIO]
|
The expected schema for pipeline input data |
output_schema |
Type[AgentIO]
|
The expected schema for pipeline output data |
agents |
List of agents in the pipeline, executed in order |
|
output_history |
List[AgentOutputT]
|
List of outputs from each agent's execution |
current_step |
Optional[int]
|
The index of the currently executing agent (1-based) |
Example
from typing import List from agenty.types import User extractor = UserExtractor() # output_schema = List[User] title_agent = TitleAgent() # input_schema = List[User] pipeline = extractor | title_agent result = await pipeline.run("Some text input")
Source code in agenty/pipeline.py
17 18 19 20 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 107 108 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
reset()
Reset the pipeline to its initial state.
Source code in agenty/pipeline.py
139 140 141 142 143 144 | |
run(input_data, name=None)
async
Run the pipeline by executing each agent in sequence.
The pipeline processes input data through a chain of agents, where each agent's output becomes the input for the next agent. Type validation is performed at each step to ensure data compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_data
|
Optional[AgentInputT]
|
The input data to process through the pipeline. Must match the pipeline's input_schema type. |
required |
name
|
Optional[str]
|
Optional name to identify this pipeline run, passed to each agent. |
None
|
Returns:
| Type | Description |
|---|---|
AgentOutputT
|
The final output after processing through all agents in the pipeline. |
AgentOutputT
|
Will match the pipeline's output_schema type. |
Raises:
| Type | Description |
|---|---|
AgentyTypeError
|
If agent's output type doesn't match the next agent's input schema. |
AgentyValueError
|
If the pipeline contains no agents. |
Example
pipeline = extractor | processor | formatter result = await pipeline.run( ... input_data="Raw text to process", ... name="document-123" ... )
Source code in agenty/pipeline.py
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |