Agents
Agent
Bases: BaseModel
, ABC
Represents a customizable agent that can interact with environments, employ skills, and leverage memory and runtimes.
Attributes:
Name | Type | Description |
---|---|---|
environment |
Environment
|
The environment with which the agent interacts. |
skills |
SkillSet
|
The skills possessed by the agent. |
memory |
LongTermMemory
|
The agent's long-term memory. Defaults to None. |
runtimes |
Dict[str, Runtime]
|
The runtimes available to the agent. Defaults to predefined runtimes. |
default_runtime |
str
|
The default runtime used by the agent. Defaults to 'openai'. |
teacher_runtimes |
Dict[str, Runtime]
|
The runtimes available to the agent's teacher. Defaults to predefined runtimes. |
default_teacher_runtime |
str
|
The default runtime used by the agent's teacher. Defaults to 'openai-gpt3'. |
Examples:
>>> from adala.environments import StaticEnvironment
>>> from adala.skills import LinearSkillSet, TransformSkill
>>> from adala.agents import Agent
>>> agent = Agent(skills=LinearSkillSet(skills=[TransformSkill()]), environment=StaticEnvironment())
>>> agent.learn() # starts the learning process
>>> predictions = agent.run() # runs the agent and returns the predictions
Source code in adala/agents/base.py
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 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 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
__rich__()
Returns a colorized and formatted representation of the Agent instance.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
A rich-formatted representation of the agent. |
Source code in adala/agents/base.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
arefine_skill(skill_name, input_variables, data=None, reapply=False, instructions=None)
async
beta v2 of Agent.learn() that is: - compatible with the newer LiteLLM runtimes - compatible with the newer response_model output formats for skills - returns chain of thought reasoning in a legible format
Limitations so far: - single skill at a time - only returns the improved input_template, doesn't modify the skill in place - no iterations/variable cost
Source code in adala/agents/base.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
|
arun(input=None, runtime=None)
async
Runs the agent on the specified input asynchronously. If no input is specified, the agent will run on the environment until it is exhausted. If input is specified, the agent will run on the input, ignoring the connected genvironment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
InternalDataFrame
|
The dataset to run the agent on. |
None
|
runtime |
str
|
The name of the runtime to use. Defaults to None, use the default runtime. |
None
|
Returns:
Name | Type | Description |
---|---|---|
InternalDataFrame |
Optional[InternalDataFrame]
|
The dataset with the agent's predictions. |
Source code in adala/agents/base.py
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 |
|
environment_validator(v)
Validates and possibly transforms the environment attribute: if the environment is an InternalDataFrame, it is transformed into a StaticEnvironment.
Source code in adala/agents/base.py
96 97 98 99 100 101 102 103 104 105 106 107 |
|
get_runtime(runtime=None)
Retrieves the specified runtime or the default runtime if none is specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runtime |
str
|
The name of the runtime to retrieve. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Runtime |
Runtime
|
The requested runtime. |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified runtime is not found. |
Source code in adala/agents/base.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
get_teacher_runtime(runtime=None)
Retrieves the specified teacher runtime or the default runtime if none is specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
runtime |
str
|
The name of the runtime to retrieve. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Runtime |
Runtime
|
The requested runtime. |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified runtime is not found. |
Source code in adala/agents/base.py
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 |
|
learn(learning_iterations=3, accuracy_threshold=0.9, update_memory=True, batch_size=None, num_feedbacks=None, runtime=None, teacher_runtime=None)
Enables the agent to learn and improve its skills based on interactions with its environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
learning_iterations |
int
|
The number of iterations for learning. Defaults to 3. |
3
|
accuracy_threshold |
float
|
The desired accuracy threshold to reach. Defaults to 0.9. |
0.9
|
update_memory |
bool
|
Flag to determine if memory should be updated after learning. Defaults to True. |
True
|
num_feedbacks |
int
|
The number of predictions to request feedback for. Defaults to None. |
None
|
runtime |
str
|
The runtime to be used for the learning process. Defaults to None. |
None
|
teacher_runtime |
str
|
The teacher runtime to be used for the learning process. Defaults to None. |
None
|
Source code in adala/agents/base.py
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 |
|
run(input=None, runtime=None, **kwargs)
Runs the agent on the specified dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input |
InternalDataFrame
|
The dataset to run the agent on. |
None
|
runtime |
str
|
The name of the runtime to use. Defaults to None, use the default runtime. |
None
|
kwargs |
Additional keyword arguments to pass to the runtime. |
{}
|
Returns: InternalDataFrame: The dataset with the agent's predictions.
Source code in adala/agents/base.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
runtimes_validator(v)
Validates and creates runtimes
Source code in adala/agents/base.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
|
select_skill_to_train(feedback, accuracy_threshold)
Selects the skill to train based on the feedback signal.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feedback |
Feedback
|
The feedback signal. |
required |
accuracy_threshold |
float
|
The accuracy threshold to use for selecting the skill to train. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of the skill to train. |
str |
str
|
The name of the skill output to train. |
float |
float
|
The accuracy score of the skill to train. |
Source code in adala/agents/base.py
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 |
|
skills_validator(v)
Validates and possibly transforms the skills attribute.
Source code in adala/agents/base.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
verify_input_parameters()
Verifies that the input parameters are valid.
Source code in adala/agents/base.py
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 |
|
create_agent_from_dict(json_dict)
Creates an agent from a JSON dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_dict |
Dict
|
The JSON dictionary to create the agent from. |
required |
Returns:
Name | Type | Description |
---|---|---|
Agent |
The created agent. |
Source code in adala/agents/base.py
448 449 450 451 452 453 454 455 456 457 458 459 460 |
|
create_agent_from_file(file_path)
Creates an agent from a YAML file:
1. Define agent reasoning workflow in workflow.yml
:
- name: reasoning
type: sample_transform
sample_size: 10
instructions: "Think step-by-step."
input_template: "Question: {question}"
output_template: "{reasoning}"
- name: numeric_answer
type: transform
instructions: >
Given math question and reasoning, provide only numeric answer after `Answer: `, for example:
Question: <math question>
Reasoning: <reasoning>
Answer: <your numerical answer>
input_template: >
Question: {question}
Reasoning: {reasoning}
output_template: >
Answer: {answer}
- Run adala math reasoning workflow on the
gsm8k
dataset:
adala run --input gsm8k --dataset-config main --dataset-split test --workflow workflow.yml
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path |
str
|
The path to the YAML file to create the agent from. |
required |
Returns:
Name | Type | Description |
---|---|---|
Agent |
The created agent. |
Source code in adala/agents/base.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
|