Step Class API Reference¶
The Step
class represents a single step in an agent's workflow, encapsulating its function, type, and configuration.
Class Definition¶
Represents a step in the agent's workflow, encapsulating its function, type, metadata, and configuration.
Attributes:
Name | Type | Description |
---|---|---|
func |
Callable[..., Any]
|
The function representing the step logic. |
step_type |
StepType
|
The type of step (e.g., THINK, ACT). |
name |
str
|
The name of the step. |
description |
Optional[str]
|
A description of the step's purpose. |
llm_config |
Optional[ModelConfig]
|
LLM configuration if the step interacts with an LLM. |
send_to_llm |
bool
|
Whether the step sends its data to an LLM. Default True. |
stream |
bool
|
Whether to stream the LLM's response |
json_output |
bool
|
Whether the step's output should be validated as JSON. Cannot be used with stream=True. |
return_type |
Optional[Type[Any]]
|
Optional type to validate output against when json_output=True. Must be a Pydantic model for validation. |
return_full_response |
bool
|
Whether to return the complete API response. Cannot be used with json_output=True. |
use_tools |
bool
|
Whether tool selection is enabled for step. Default True. |
tool_selection_config |
Optional[ToolSelectionConfig]
|
Configuration for tool selection behavior. |
tool_model |
Optional[ModelConfig]
|
Optional specific model to use for tool selection. |
config |
StepConfig
|
Configuration settings for the step. |
metadata |
Optional[FunctionMetadata]
|
Metadata extracted from the step function. |
tool_decisions |
Optional[List[ToolCallDecision]]
|
Records of tool selection and execution decisions. |
Example
Create a step with tool configuration:
Notes
- Streaming and validation (json_output, return_type) cannot be used together
- Return type validation requires a Pydantic model type
Source code in clientai/agent/steps/base.py
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 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
__post_init__()
¶
Validate step values after initialization.
Source code in clientai/agent/steps/base.py
__str__()
¶
Provide a human-readable string representation of the step.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A description of the step, including its name, type, and optional details. |
Example
Print a step's string representation:
Source code in clientai/agent/steps/base.py
can_execute_with(input_data)
¶
Check if the step can execute with the provided input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_data
|
Any
|
The input data to validate |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the input matches the step's expected input type |
Example
Validate input data:
Source code in clientai/agent/steps/base.py
create(func, step_type, name=None, description=None, llm_config=None, send_to_llm=None, stream=False, json_output=False, return_type=None, return_full_response=False, use_tools=True, tool_selection_config=None, tool_model=None, step_config=None)
classmethod
¶
Create and validate a new step.
Factory method for creating steps with comprehensive configuration options.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func
|
Callable[..., Any]
|
Function implementing the step logic |
required |
step_type
|
StepType
|
Type classification for the step |
required |
name
|
Optional[str]
|
Optional custom name (defaults to function name) |
None
|
description
|
Optional[str]
|
Optional step description |
None
|
llm_config
|
Optional[ModelConfig]
|
Optional LLM configuration |
None
|
send_to_llm
|
Optional[bool]
|
Whether to send step output to LLM |
None
|
stream
|
bool
|
Whether to stream LLM responses |
False
|
json_output
|
bool
|
Whether to validate the step's output as JSON. Cannot be used with stream=True. |
False
|
return_type
|
Optional[Type[Any]]
|
Type to validate output against when json_output=True. Must be a Pydantic model. |
None
|
return_full_response
|
bool
|
Whether to return the complete API response. Cannot be used with json_output=True. |
False
|
json_output
|
bool
|
Whether LLM should return JSON |
False
|
use_tools
|
bool
|
Whether to enable tool selection |
True
|
tool_selection_config
|
Optional[ToolSelectionConfig]
|
Optional tool selection configuration |
None
|
tool_model
|
Optional[ModelConfig]
|
Optional specific model for tool selection |
None
|
step_config
|
Optional[StepConfig]
|
Optional step-specific configuration |
None
|
Returns:
Name | Type | Description |
---|---|---|
Step |
Step
|
Validated step instance |
Raises:
Type | Description |
---|---|
ValueError
|
If step name is invalid or function lacks required annotations |
Example
Create step with tool selection:
step = Step.create(
func=analyze_data,
step_type=StepType.THINK,
name="analyze",
description="Analyzes input data",
use_tools=True,
tool_selection_config=ToolSelectionConfig(
confidence_threshold=0.8
)
)
Create step with custom model:
step = Step.create(
func=process_data,
step_type=StepType.ACT,
llm_config=ModelConfig(
name="gpt-4",
temperature=0.7
),
stream=True
)
Create step with validation:
Source code in clientai/agent/steps/base.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
|
is_compatible_with(other)
¶
Check if this step's input is compatible with another step's output.
Determines if steps can be connected in a workflow by comparing their input/output types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Step
|
The step to check compatibility with |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if this step can accept the other step's output type |
Example
Check step compatibility: