amphibious¶
Amphibious Agent Framework — Dual-Mode Agent Orchestration.
A framework for building agents that can operate in both LLM-driven (agent) and deterministic (workflow) modes, with automatic fallback between them.
Architecture Layers
Abstraction Layer (Data Exposure): - Exposure: Base abstraction for field-level data management - LayeredExposure: Supports progressive disclosure (summary + per-item details) - EntireExposure: Summary only, no per-item detail queries - Context: Base class for agent context with automatic Exposure field detection
Implementation Layer — Context: - Step: A single execution step with content, result, and metadata - Skill: A skill definition following SKILL.md format - CognitiveTools: Tool management (EntireExposure) - CognitiveSkills: Skill management with progressive disclosure (LayeredExposure) - CognitiveHistory: Execution history with layered memory (LayeredExposure) - CognitiveContext: The default cognitive context combining all above
Implementation Layer — Worker (Think Unit): - CognitiveWorker: Pure thinking unit of one observe-think-act cycle. Cognitive policies (acquiring, rehearsal, reflection) enable multi-round thinking within a single call.
Orchestration Layer: - AmphibiousAutoma: Dual-mode agent engine (agent mode + workflow mode) - think_unit: Descriptor for declaring think units (used in on_agent) - ActionCall, HumanCall, AgentCall: Workflow yield types (used in on_workflow) - ErrorStrategy: Error handling strategies (RAISE, IGNORE, RETRY)
Example
class MyAgent(AmphibiousAutoma[CognitiveContext]): ... main_think = think_unit(CognitiveWorker.inline("Execute step"), max_attempts=20) ... async def on_agent(self, ctx): ... await self.main_think ... ctx = await MyAgent(llm=llm).arun(goal="Complete the task")
Exposure ¶
Bases: ABC, Generic[T]
Abstract base class for field-level data exposure.
Manages list-like data (e.g., history records, tool lists) with a unified interface. Subclasses determine the exposure strategy: - LayeredExposure: supports progressive disclosure (summary + per-item details) - EntireExposure: only provides summary (no per-item details)
Methods:
| Name | Description |
|---|---|
add | Add an element and return its index. |
summary | Return a list of summary strings for all elements. |
get_all | Return a copy of all elements. |
Source code in bridgic/amphibious/_context.py
add ¶
Add an element to the collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item | T | The element to add. | required |
Returns:
| Type | Description |
|---|---|
int | Index of the newly added element (0-based). |
Source code in bridgic/amphibious/_context.py
set_llm ¶
Set the LLM for this exposure.
Stored as self._llm and available to subclasses that need it (e.g. CognitiveHistory uses it for compression). Called automatically by Context.set_llm() for fields marked with json_schema_extra={"use_llm": True}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm | Any | LLM instance to store. | required |
Source code in bridgic/amphibious/_context.py
LayeredExposure ¶
Bases: Exposure[T]
Exposure with progressive disclosure support.
Provides two-level information architecture: - summary(): overview of all items - get_details(index): detailed information for a specific item
Use this for data where the LLM may need to request details about specific items (e.g., execution history, skills).
Disclosure state is owned internally: once revealed, an item's detail is cached in _revealed. Call reset_revealed() to clear all cached reveals (e.g., at phase boundaries in a multi-phase agent).
Source code in bridgic/amphibious/_context.py
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 | |
reveal ¶
Get and cache detailed information for a specific element.
Returns the cached value if already revealed; otherwise calls get_details(index), stores the result, and returns it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | Element index (0-based). | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Detailed information string, or None if index is invalid. |
Source code in bridgic/amphibious/_context.py
reset_revealed ¶
Clear all cached reveals.
Use at phase boundaries to allow the LLM to re-request details that were disclosed in a previous phase.
summary ¶
abstractmethod Generate summary strings for all elements.
Returns:
| Type | Description |
|---|---|
List[str] | One summary string per element. |
get_details ¶
abstractmethod Get detailed information for a specific element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | Element index (0-based). | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Detailed information string, or None if index is invalid. |
Source code in bridgic/amphibious/_context.py
EntireExposure ¶
Bases: Exposure[T]
Exposure without progressive disclosure.
Only provides summary() - all information is exposed at once. Use this for data where per-item details are not needed or the full information should always be available (e.g., tools).
Source code in bridgic/amphibious/_context.py
summary ¶
abstractmethod Generate summary strings for all elements.
Returns:
| Type | Description |
|---|---|
List[str] | One summary string per element. |
Context ¶
Bases: BaseModel
Base class for agent context with automatic Exposure field detection.
Provides unified access to context data through summary and detail retrieval. Automatically discovers Exposure-typed fields and distinguishes between LayeredExposure (supports details) and EntireExposure (summary only).
Methods:
| Name | Description |
|---|---|
summary | Get a dictionary of all field values or Exposure summaries. |
get_details | Get detailed information for a specific LayeredExposure item. |
get_revealed_items | Get all (field, index) pairs that have been revealed so far. |
reset_revealed | Clear reveal caches on all LayeredExposure fields. |
Examples:
Source code in bridgic/amphibious/_context.py
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 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 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 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 | |
get_hidden_fields ¶
classmethod Get list of field names that should be hidden from summary.
Returns:
| Type | Description |
|---|---|
List[str] | Field names where display is explicitly set to False. |
Examples:
Source code in bridgic/amphibious/_context.py
set_llm ¶
Propagate an LLM to all Exposure fields that opt in via use_llm=True.
Called by AmphibiousAutoma at run start. Fields opt in by declaring:
1 2 3 | |
Only Exposure fields are considered; non-Exposure fields are ignored. Exposure fields without use_llm=True are also ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm | Any | The LLM instance to propagate. | required |
Source code in bridgic/amphibious/_context.py
summary ¶
Generate a summary dictionary with formatted strings for each field.
Automatically filters out fields marked with json_schema_extra={"display": False}. Subclasses should override this to provide custom formatting for each field. The returned dictionary maps field names to their formatted string representations.
Returns:
| Type | Description |
|---|---|
Dict[str, str] | Field name to formatted summary string mapping. Each value should be a complete, formatted string ready for prompt inclusion. Hidden fields (display=False) are excluded. |
Source code in bridgic/amphibious/_context.py
format_summary ¶
format_summary(
include: Optional[List[str]] = None,
exclude: Optional[List[str]] = None,
separator: str = "\n",
) -> str
Format the summary dictionary into a string with field selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include | Optional[List[str]] | If provided, only include these fields (takes priority over exclude). | None |
exclude | Optional[List[str]] | If provided, exclude these fields from the output. | None |
separator | str | Separator between field summaries. Default is newline. | '\n' |
Returns:
| Type | Description |
|---|---|
str | Formatted summary string with selected fields. |
Examples:
Source code in bridgic/amphibious/_context.py
get_field ¶
Get field information with type-aware return.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field | str | Name of the field. | required |
Returns:
| Type | Description |
|---|---|
Tuple[Optional[List[str]], Any] |
|
Source code in bridgic/amphibious/_context.py
get_details ¶
Get detailed information for a LayeredExposure field item.
Only works for LayeredExposure fields. Returns None for EntireExposure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field | str | Name of the Exposure field. | required |
idx | int | Item index within the field (0-based). | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Detailed information string, or None if: - Field doesn't exist - Field is not a LayeredExposure - Index is invalid |
Source code in bridgic/amphibious/_context.py
get_revealed_items ¶
Return all (field_name, index) pairs that have been revealed across all LayeredExposure fields on this context.
Returns:
| Type | Description |
|---|---|
List[Tuple[str, int]] | Ordered list of (field_name, item_index) that have cached reveals. |
Source code in bridgic/amphibious/_context.py
reset_revealed ¶
Reset reveal state on all LayeredExposure fields.
Equivalent to calling field.reset_revealed() on every LayeredExposure field. Use at phase boundaries so the next phase can request fresh details.
Source code in bridgic/amphibious/_context.py
Step ¶
Bases: BaseModel
A single execution step with content, result, and metadata.
Used by: _context.py (CognitiveHistory, CognitiveContext.add_info), _amphibious_automa.py (_action, _record_trace_step)
Source code in bridgic/amphibious/_type.py
Skill ¶
Bases: BaseModel
A skill definition following SKILL.md format.
Used by: _context.py (CognitiveSkills)
Source code in bridgic/amphibious/_type.py
CognitiveTools ¶
Bases: EntireExposure[ToolSpec]
Manages available tools (EntireExposure - no progressive disclosure).
All tool information is exposed in summary. Use get_all() to access the full ToolSpec list when detailed information is needed.
Source code in bridgic/amphibious/_context.py
summary ¶
Generate summary strings for all tools.
Returns:
| Type | Description |
|---|---|
List[str] | Summary for each tool in format: "• {name}: {description}". |
Source code in bridgic/amphibious/_context.py
CognitiveSkills ¶
Bases: LayeredExposure[Skill]
Manages available skills with progressive disclosure (LayeredExposure).
Provides skill storage, summary generation (name + description), and detailed content retrieval (full SKILL.md content).
Methods:
| Name | Description |
|---|---|
add | Add a skill from Skill object, file path, or SKILL.md markdown text. |
add_from_markdown | Parse and add a skill from SKILL.md format. |
get_by_name | Get a skill by its name. |
Source code in bridgic/amphibious/_context.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
add ¶
Add a skill from various input types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item | Union[Skill, str] |
| required |
Returns:
| Type | Description |
|---|---|
int | Index of the newly added skill. |
Raises:
| Type | Description |
|---|---|
TypeError | If item is not a Skill or str. |
Source code in bridgic/amphibious/_context.py
add_from_markdown ¶
Parse a SKILL.md file and add it as a skill.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown_text | str | Full content of a SKILL.md file (YAML frontmatter + markdown). | required |
Returns:
| Type | Description |
|---|---|
int | Index of the newly added skill. |
Raises:
| Type | Description |
|---|---|
ValueError | If the markdown doesn't contain valid YAML frontmatter or required fields. |
Source code in bridgic/amphibious/_context.py
add_from_file ¶
Load and add a skill from a SKILL.md file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path | str | Path to the SKILL.md file. | required |
Returns:
| Type | Description |
|---|---|
int | Index of the newly added skill. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If the file doesn't exist. |
ValueError | If the file doesn't contain valid SKILL.md format. |
Source code in bridgic/amphibious/_context.py
load_from_directory ¶
Load all SKILL.md files from a directory recursively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory | str | Path to the directory containing SKILL.md files. | required |
pattern | str | Glob pattern for finding skill files (default: "**/SKILL.md"). | '**/SKILL.md' |
Returns:
| Type | Description |
|---|---|
int | Number of skills successfully loaded. |
Source code in bridgic/amphibious/_context.py
summary ¶
Generate summary strings for all skills.
Returns:
| Type | Description |
|---|---|
List[str] | Summary for each skill in format: "/{name} - {description}". |
Source code in bridgic/amphibious/_context.py
get_details ¶
Get detailed information for a specific skill (full SKILL.md content).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | Skill index (0-based). | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Full skill details including frontmatter and markdown content. Returns None if index is out of range. |
Source code in bridgic/amphibious/_context.py
CognitiveHistory ¶
Bases: LayeredExposure[Step]
Manages execution history with layered memory architecture.
Memory layers: - Working memory (most recent N steps): Full details displayed directly - Short-term memory (next N steps): Summary only, details available on request - Long-term memory (older steps): - Pending buffer: brief summaries, waiting for batch compression - Compressed summary: LLM-generated concise summary
Compression is batched: LLM is only called when the pending buffer reaches compress_threshold, reducing LLM calls by a factor of compress_threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
working_memory_size | int | Number of recent steps to show with full details (default: 5). | 5 |
short_term_size | int | Number of steps to show as summary before working memory (default: 20). | 20 |
compress_threshold | int | Number of pending long-term steps to accumulate before triggering one batch LLM compression (default: 5). | 10 |
Source code in bridgic/amphibious/_context.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 | |
add ¶
add(item: Step) -> int
Add a step to history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item | Step | The step to add. | required |
Returns:
| Type | Description |
|---|---|
int | Index of the newly added step. |
Source code in bridgic/amphibious/_context.py
compress_if_needed ¶
async Compress old history if needed.
Call this after adding steps to check and perform compression. Requires LLM to be set via set_llm().
Returns:
| Type | Description |
|---|---|
bool | True if compression was performed, False otherwise. |
Source code in bridgic/amphibious/_context.py
needs_compression ¶
Check if pending long-term steps have reached the compression threshold.
summary ¶
Generate layered summary.
Returns:
| Type | Description |
|---|---|
List[str] | Formatted strings for each memory layer: - Long-term compressed: LLM-generated summary (if exists) - Long-term pending: brief summaries of steps awaiting compression - Short-term: step summaries with indices (queryable) - Working: full step details with indices |
Source code in bridgic/amphibious/_context.py
get_details ¶
Get detailed information for a specific step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index | int | Step index (0-based). | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Formatted step details, or None if index is out of range. |
Source code in bridgic/amphibious/_context.py
CognitiveContext ¶
Bases: Context
Default cognitive context providing all fields needed by CognitiveWorker.
Combines goal, tools, skills, execution history, and observation into a unified context. Users can extend this class to add custom fields.
Attributes:
| Name | Type | Description |
|---|---|---|
goal | str | The goal to achieve. |
tools | CognitiveTools | Available tools (EntireExposure — summary only, no per-item details). |
skills | CognitiveSkills | Available skills (LayeredExposure — supports progressive disclosure). |
cognitive_history | CognitiveHistory | History of cognitive steps (LayeredExposure — supports progressive disclosure). |
observation | Optional[str] | Current observation from the last observation phase (hidden from summary). |
Examples:
Source code in bridgic/amphibious/_context.py
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 | |
summary ¶
Generate a summary dictionary with formatted strings for each field.
Returns a dictionary where each key is a field name and each value is a formatted string ready for prompt inclusion. Includes previously disclosed details from all LayeredExposure fields.
Returns:
| Type | Description |
|---|---|
Dict[str, str] | Field name to formatted summary string mapping: - goal: "Goal: {goal}" - tools: formatted tool list - skills: formatted skill list with indices - cognitive_history: formatted history with indices - disclosed_details: previously disclosed details (if any) |
Source code in bridgic/amphibious/_context.py
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 | |
CognitiveWorker ¶
Bases: GraphAutoma
Cognitive worker: pure thinking unit of an agent.
A CognitiveWorker represents one thinking cycle and is responsible for "what to think and how to think". Observation and action execution are handled by AmphibiousAutoma as shared infrastructure.
Subclass and override template methods to customize behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm | Optional[BaseLlm] | LLM used for thinking. Can be None if the agent will inject one via set_llm(). | None |
enable_rehearsal | bool | Enable rehearsal policy (predict tool execution outcomes). Default is False. | False |
enable_reflection | bool | Enable reflection policy (assess information quality). Default is False. | False |
verbose | bool | Enable logging of thinking process. Default is False. | None |
verbose_prompt | bool | Enable logging of full prompts sent to LLM. Default is False. | None |
Class Attributes
output_schema : Optional[Type[BaseModel]] If set, the worker produces a typed Pydantic instance directly using the output_schema as the LLM constraint. The agent's action() phase is skipped entirely. await think_unit returns the typed instance. Policy rounds (rehearsal/reflection) still run if enabled.
Template Methods (override in subclasses)
thinking() -> str Return the thinking prompt (how to decide next steps). Must be implemented.
build_messages(think_prompt, tools_description, output_instructions, context_info) Assemble the final messages for the thinking phase. Returns List[Message].
observation(context, default_observation) -> Union[str, _DELEGATE] Enhance or customize observation. Default returns _DELEGATE. Return _DELEGATE to delegate observation to AmphibiousAutoma.
before_action(decision_result, context) -> Any Verify/adjust the decision before execution. Called by AmphibiousAutoma._action().
Examples:
Source code in bridgic/amphibious/_cognitive_worker.py
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 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 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 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 | |
set_llm ¶
set_llm(llm: BaseLlm) -> None
Set the LLM used for thinking and tool selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm | BaseLlm | LLM instance to use. Replaces any previously set LLM. | required |
observation ¶
async observation(context: CognitiveContext) -> Any
Enhance or customize the observation before thinking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context | CognitiveContext | The cognitive context. | required |
Returns:
| Type | Description |
|---|---|
Any | _DELEGATE to delegate observation to AmphibiousAutoma.observation(). A string to use as the observation directly. |
Examples:
Source code in bridgic/amphibious/_cognitive_worker.py
thinking ¶
async Define how to think about the next step(s). Must be implemented.
The returned prompt is used to guide the LLM. This is the core template method.
Returns:
| Type | Description |
|---|---|
str | Thinking prompt for the LLM. |
Examples:
Source code in bridgic/amphibious/_cognitive_worker.py
build_messages ¶
async build_messages(
think_prompt: str,
tools_description: str,
output_instructions: str,
context_info: str,
) -> List[Message]
Assemble the final messages for the thinking phase.
Override this method to customize how the prompt components are structured across messages. This allows you to reorder, modify, or add to the message list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
think_prompt | str | The thinking prompt from the thinking() method. | required |
tools_description | str | Formatted description of available tools and skills. | required |
output_instructions | str | Instructions for the output format (finish, steps/step_content, etc.). | required |
context_info | str | Context information including goal, status, history, and fetched details. | required |
Returns:
| Type | Description |
|---|---|
List[Message] | Messages to be sent to the LLM. Default structure: - Message 1 (system): think_prompt + tools_description (if non-empty) + output_instructions - Message 2 (user): context_info |
Examples:
Source code in bridgic/amphibious/_cognitive_worker.py
before_action ¶
async before_action(
decision_result: Any, context: CognitiveContext
) -> Any
Verify and optionally adjust the output before execution.
Returns _DELEGATE by default, which delegates to the agent-level before_action() method. Override to intercept and modify tool calls at the worker level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decision_result | Any | The result of the decision. | required |
context | CognitiveContext | Current cognitive context. | required |
Returns:
| Type | Description |
|---|---|
Any | Verified/adjusted decision result, or |
Examples:
Source code in bridgic/amphibious/_cognitive_worker.py
after_action ¶
async after_action(
step_result: Any, ctx: CognitiveContext
) -> Any
Worker-level post-action hook for side effects on the context.
Returns _DELEGATE by default, which chains to the agent-level after_action() method. Override this hook to mutate custom context fields or perform side effects at the worker level.
The return value is a control signal, not a data channel: - Return _DELEGATE to also invoke the agent-level after_action. - Return anything else to suppress the agent-level hook. The returned value itself is discarded — the step_result stored in history is never replaced by this hook. Perform any mutation by updating ctx or step_result in place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_result | Any | The result of the action step (typically a | required |
ctx | CognitiveContext | Current cognitive context. | required |
Returns:
| Type | Description |
|---|---|
Any |
|
Examples:
Source code in bridgic/amphibious/_cognitive_worker.py
inline ¶
classmethod inline(
thinking_prompt: str,
llm: Optional[BaseLlm] = None,
enable_rehearsal: bool = False,
enable_reflection: bool = False,
verbose: Optional[bool] = None,
verbose_prompt: Optional[bool] = None,
output_schema: Optional[Type[BaseModel]] = None,
) -> CognitiveWorker
Create a simple CognitiveWorker from a thinking prompt string.
Convenience factory for cases where you only need to customize the thinking prompt without overriding other methods.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thinking_prompt | str | The thinking prompt to use. | required |
llm | Optional[BaseLlm] | LLM instance to use. | None |
enable_rehearsal | bool | Enable rehearsal policy. | False |
enable_reflection | bool | Enable reflection policy. | False |
verbose | Optional[bool] | Enable verbose logging. | None |
verbose_prompt | Optional[bool] | Enable prompt logging. | None |
output_schema | Optional[Type[BaseModel]] | If set, the worker produces a typed instance directly instead of going through the standard tool-call loop. | None |
Returns:
| Type | Description |
|---|---|
CognitiveWorker | A worker instance with the specified thinking prompt. |
Examples:
Source code in bridgic/amphibious/_cognitive_worker.py
arun ¶
async arun(
*args: Any,
feedback_data: Optional[
Union[
InteractionFeedback, List[InteractionFeedback]
]
] = None,
**kwargs: Any
) -> Any
Execute the thinking phase. Observation must be pre-set in context.observation.
Source code in bridgic/amphibious/_cognitive_worker.py
AmphibiousAutoma ¶
Bases: GraphAutoma, Generic[CognitiveContextT]
Base class for amphibious agents — dual-mode orchestration engine.
Supports three execution modes: - Agent mode (on_agent): LLM-driven observe-think-act cycles via think_unit - Workflow mode (on_workflow): Deterministic step execution via yield - Amphiflow mode (on_workflow + on_agent): workflow-first with automatic agent fallback when a step fails
Subclasses define behavior by implementing on_agent() and/or on_workflow(). Under RunMode.AUTO (the default) the runtime picks the mode from which template methods are overridden:
- only
on_agentoverridden →RunMode.AGENT - only
on_workflowoverridden →RunMode.WORKFLOW - both overridden →
RunMode.AMPHIFLOW
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm | Optional[BaseLlm] | Default LLM for workers and auxiliary tasks (e.g., history compression). Individual workers can specify their own LLM. | None |
name | Optional[str] | Optional name for the agent instance. | None |
verbose | bool | Enable logging of execution summary (tokens, time). Default is False. | False |
Examples:
Source code in bridgic/amphibious/_amphibious_automa.py
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 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 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 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 | |
final_answer property ¶
The final answer produced by the last arun() call.
Automatically captured from the step_content of the finishing step (agent mode) or the last executed step (workflow mode). Can be overridden explicitly via set_final_answer().
set_final_answer ¶
Explicitly set the final answer.
Call this inside on_agent() or on_workflow() to override the auto-captured value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
answer | str | The final answer text. | required |
Source code in bridgic/amphibious/_amphibious_automa.py
request_human ¶
async Request input from the human operator.
This is the primary entry point for code-level human-in-the-loop calls inside on_agent() (between think units) or from the request_human_tool closure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The question or message to present to the human. | required |
timeout | Optional[float] | Seconds to wait before raising | None |
Returns:
| Type | Description |
|---|---|
str | The human's response text. |
Raises:
| Type | Description |
|---|---|
TimeoutError | If no response is received within |
Source code in bridgic/amphibious/_amphibious_automa.py
observation ¶
async Agent-level default observation, shared across all workers.
Called by _run() before each thinking phase. Workers can enhance this via their own observation() method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx | CognitiveContextT | The cognitive context. | required |
Returns:
| Type | Description |
|---|---|
Optional[str] | Custom observation text, or None. |
Source code in bridgic/amphibious/_amphibious_automa.py
on_agent ¶
async Agent mode: LLM-driven orchestration logic.
Override this method to define how think_units are orchestrated. Use standard Python control flow combined with await self.think_unit calls.
A subclass may override this, on_workflow, or both. The default implementation is a no-op so that subclasses which only implement on_workflow remain instantiable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx | CognitiveContextT | The cognitive context, used for accessing state and conditions. | required |
Examples:
Source code in bridgic/amphibious/_amphibious_automa.py
on_workflow ¶
async on_workflow(
ctx: CognitiveContextT,
) -> AsyncGenerator[
Union[ActionCall, HumanCall, AgentCall], None
]
Workflow mode: deterministic execution as an async generator.
Override this method to define a deterministic workflow. When overridden, arun() automatically routes to workflow mode instead of on_agent().
Three yield types are supported: - ActionCall — deterministic single-tool execution - HumanCall — pause and request human input (returned as str via asend) - AgentCall — delegate a sub-task to LLM agent mode
The generator exhausting signals workflow completion — no finish signal needed. Use result = yield ActionCall(...) to receive tool execution results via asend().
Examples:
Source code in bridgic/amphibious/_amphibious_automa.py
before_action ¶
async Agent-level before_action hook, shared across all workers.
Called when a worker's before_action() returns _DELEGATE. Override to intercept and modify tool calls at the agent level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decision_result | Any | The decision result (typically List[Tuple[ToolCall, ToolSpec]]). | required |
ctx | CognitiveContextT | The cognitive context. | required |
Returns:
| Type | Description |
|---|---|
Any | Verified/adjusted decision result. |
Source code in bridgic/amphibious/_amphibious_automa.py
action_tool_call ¶
async action_tool_call(
tool_list: List[Tuple[ToolCall, ToolSpec]],
context: CognitiveContextT,
) -> ActionResult
Execute tool calls concurrently and collect results.
Override this method to customize tool execution behavior (e.g., sequential execution, rate limiting, sandboxing).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_list | List[Tuple[ToolCall, ToolSpec]] | Matched tool call / spec pairs to execute. | required |
context | CognitiveContextT | The current cognitive context. | required |
Returns:
| Type | Description |
|---|---|
ActionResult | Aggregated results with per-tool success/failure status. |
Source code in bridgic/amphibious/_amphibious_automa.py
action_custom_output ¶
async Handle structured output from a worker with output_schema set.
Called instead of action_tool_call() when the worker produces a typed Pydantic instance (via output_schema) rather than tool calls. Override to post-process or validate structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decision_result | Any | The structured output instance produced by the worker. | required |
context | CognitiveContextT | The current cognitive context. | required |
Returns:
| Type | Description |
|---|---|
Any | The (optionally processed) result to store in execution history. |
Source code in bridgic/amphibious/_amphibious_automa.py
after_action ¶
async Agent-level after_action hook.
Called after action execution and before the result is returned. Override to update custom context fields based on tool results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_result | Any | The result of the action step. | required |
ctx | CognitiveContextT | The current cognitive context. | required |
Source code in bridgic/amphibious/_amphibious_automa.py
human_input ¶
async Template method invoked when the agent requests human input.
Override this in your subclass to integrate with your UI or messaging layer. The default implementation reads from stdin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data | Dict[str, Any] | Event payload — always contains | required |
Returns:
| Type | Description |
|---|---|
str | The human's response text. |
Source code in bridgic/amphibious/_amphibious_automa.py
snapshot ¶
async snapshot(
*,
goal: Optional[str] = None,
keep_revealed: Optional[Dict[str, List[int]]] = None,
**snapshot_fields
)
Temporarily override context fields for the duration of the block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal | Optional[str] | Temporary goal injected into the context so the LLM knows the purpose of this phase. | None |
keep_revealed | Optional[Dict[str, List[int]]] | Passed to | None |
**snapshot_fields | Additional context fields to temporarily override during this phase. | {} |
Source code in bridgic/amphibious/_amphibious_automa.py
router ¶
async router(
mode: RunMode, max_consecutive_fallbacks: int
) -> str
Router worker: dispatches to the correct execution mode.
RunMode.AUTO is resolved upstream in arun(), so this worker always receives a concrete mode.
Source code in bridgic/amphibious/_amphibious_automa.py
arun ¶
async arun(
*,
context: Optional[CognitiveContextT] = None,
trace_running: bool = False,
mode: Optional[RunMode] = AUTO,
max_consecutive_fallbacks: int = 1,
**kwargs
) -> str
Run the agent.
Routes to one of the execution modes: 1. Agent mode — LLM-driven on_agent() path. 2. Workflow mode — deterministic on_workflow() path (no fallback). 3. Amphiflow mode — on_workflow() with automatic agent fallback. 4. Auto mode (default) — resolved from which template methods the subclass overrides: both → AMPHIFLOW, only on_workflow → WORKFLOW, only on_agent → AGENT.
Context initialization has two paths: 1. Pre-created: arun(context=my_ctx) 2. Auto-created: arun(goal="...", tools=[...], skills=[...])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context | Optional[CognitiveContextT] | Pre-created context object. If provided, uses this context directly. | None |
trace_running | bool | If True, enables trace capture via AgentTrace during execution. | False |
mode | Optional[RunMode] | Execution mode. | AUTO |
max_consecutive_fallbacks | int | Maximum consecutive workflow step failures before switching to full agent mode. Only applies to amphiflow mode. Default is 1. | 1 |
**kwargs | Arguments passed to CognitiveContext constructor when | {} |
Returns:
| Type | Description |
|---|---|
str | Summary of the context after execution. |
Source code in bridgic/amphibious/_amphibious_automa.py
1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 | |
AgentTrace ¶
Flat trace recorder that captures each observe-think-act cycle.
record_step() appends step data to the execution path. build() returns the collected steps as a structured dict. save() / load() provide JSON serialization.
Source code in bridgic/amphibious/_amphibious_automa.py
record_step ¶
Append a trace step to the execution path.
build ¶
Return collected trace data as a structured dict.
Source code in bridgic/amphibious/_amphibious_automa.py
save ¶
Serialize the trace to a JSON file.
Source code in bridgic/amphibious/_amphibious_automa.py
ThinkUnitDescriptor ¶
Python descriptor enabling class-level think unit declaration.
When accessed on an instance (self.main_think), returns a _BoundThinkUnit that is awaitable and supports .until().
When accessed on the class, returns the descriptor itself.
Source code in bridgic/amphibious/_amphibious_automa.py
RunMode ¶
Bases: str, Enum
The mode of the run.
Used by: _amphibious_automa.py (arun, router)
Source code in bridgic/amphibious/_type.py
DetailRequest ¶
Bases: BaseModel
Request for detailed information about a specific item in a LayeredExposure field.
Used by: _cognitive_worker.py (acquiring policy)
Source code in bridgic/amphibious/_type.py
ToolArgument ¶
Bases: BaseModel
A single tool argument as name-value pair.
Used by: _cognitive_worker.py (StepToolCall), _amphibious_automa.py (action phase)
Source code in bridgic/amphibious/_type.py
StepToolCall ¶
Bases: BaseModel
A single tool call specification.
Used by: _cognitive_worker.py (ThinkModel output), _amphibious_automa.py (action phase)
Source code in bridgic/amphibious/_type.py
WorkflowDecision ¶
Bases: BaseModel
Single-step deterministic decision for workflow mode.
Used by: _amphibious_automa.py (_run_workflow, ActionCall)
Source code in bridgic/amphibious/_type.py
ActionCall dataclass ¶
Yielded by on_workflow() for deterministic single-tool execution.
Replaces the removed step() shorthand function. Each instance wraps exactly one tool call together with an optional CognitiveWorker override.
Used by: _amphibious_automa.py (_run_workflow)
Usage:: yield ActionCall("navigate_to", url="http://example.com") yield ActionCall("click_element_by_ref", description="Click submit", ref="e42") result = yield ActionCall("fill_field", name="user", value="john", worker=my_worker)
Source code in bridgic/amphibious/_type.py
HumanCall dataclass ¶
Yielded by on_workflow() to pause execution and request human input.
Execution is suspended until the human provides a response, which is returned to the generator via asend() as a plain string.
Used by: _amphibious_automa.py (_run_workflow)
Usage:: feedback = yield HumanCall(prompt="Please verify the result (yes/no):")
Source code in bridgic/amphibious/_type.py
AgentCall dataclass ¶
Yielded by on_workflow() to fall back to agent mode for a sub-task.
By default a clean context is used (fresh history, full tool set). Provide explicit values to override specific context fields.
Used by: _amphibious_automa.py (_run_workflow)
Usage::
1 | |
Source code in bridgic/amphibious/_type.py
ErrorStrategy ¶
Bases: Enum
Error handling strategy for worker execution via _run().
Used by: _amphibious_automa.py (_run method), _amphibious_automa.py (ThinkUnitDescriptor)
Source code in bridgic/amphibious/_type.py
ActionResult ¶
Bases: BaseModel
Overall result of the action phase (one or more tool executions).
Used by: _amphibious_automa.py (action_tool_call, _record_trace_step)
Source code in bridgic/amphibious/_type.py
ActionStepResult ¶
Bases: BaseModel
Result of executing one tool in the action phase.
Used by: _amphibious_automa.py (action_tool_call)
Source code in bridgic/amphibious/_type.py
ToolResult dataclass ¶
Single tool execution result returned to workflow generator via asend().
Used by: _amphibious_automa.py (_run_workflow), on_workflow user code
Source code in bridgic/amphibious/_type.py
TraceStep ¶
Bases: BaseModel
Record of one observe-think-act cycle.
Used by: _amphibious_automa.py (AgentTrace.build)
Source code in bridgic/amphibious/_type.py
RecordedToolCall ¶
Bases: BaseModel
A complete record of one tool invocation.
Used by: _amphibious_automa.py (AgentTrace.build)
Source code in bridgic/amphibious/_type.py
StepOutputType ¶
Bases: str, Enum
Discriminator for the kind of output a trace step produced.
Used by: _amphibious_automa.py (AgentTrace, _record_trace_step)
Source code in bridgic/amphibious/_type.py
think_unit ¶
think_unit(
worker: CognitiveWorker,
*,
until: Optional[
Union[
Callable[..., bool],
Callable[..., Awaitable[bool]],
]
] = None,
max_attempts: int = 1,
tools: Optional[List[str]] = None,
skills: Optional[List[str]] = None,
on_error: ErrorStrategy = RAISE,
max_retries: int = 0
) -> ThinkUnitDescriptor
Declare a think unit for use in on_agent().
Factory function that returns a ThinkUnitDescriptor. Use as a class variable::
1 2 3 4 5 6 7 8 9 | |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker | CognitiveWorker | The worker template. A fresh clone is created for each execution. | required |
until | Optional callable | Loop condition: repeats until this returns True or LLM signals finish. | None |
max_attempts | int | Maximum execution attempts (default 1 = single shot). | 1 |
tools | Optional[List[str]] | Tool filter: only these tools are visible to the worker. | None |
skills | Optional[List[str]] | Skill filter: only these skills are visible to the worker. | None |
on_error | ErrorStrategy | Error handling strategy (default: RAISE). | RAISE |
max_retries | int | Max retries for RETRY strategy. | 0 |
Source code in bridgic/amphibious/_amphibious_automa.py
create_project ¶
Create a new amphibious automa project with standard directory structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name | str | Project directory name. | required |
base_dir | str | Parent directory. Defaults to current working directory. | None |
task | str | Initial task description for task.md. | None |
Returns:
| Type | Description |
|---|---|
Path | Path to the created project directory. |