Multi-agent¶
Composition¶
SequentialPipeline ¶
Bases: BaseModel
Run agents in order, passing each output as the next agent's prompt.
Each agent receives either the original task (first agent) or the previous agent's output (subsequent agents). A prompt_template can customize how the previous output is passed.
Example
pipeline = SequentialPipeline( ... agents=[researcher, writer, editor], ... prompt_template="Based on the following:\n{previous_output}\n\nOriginal task: {task}", ... ) result = await pipeline.run("Write about quantum computing")
run
async
¶
Execute agents sequentially, chaining outputs.
Source code in src/locus/agent/composition.py
ParallelPipeline ¶
Bases: BaseModel
Run agents concurrently and merge their results.
All agents receive the same task (or custom prompts via task_map). Results are collected and merged using the merge_strategy.
Example
pipeline = ParallelPipeline( ... agents=[fact_checker, analyst, summarizer], ... merge_strategy="concatenate", ... ) result = await pipeline.run("Analyze climate change impacts")
run
async
¶
Execute agents in parallel and merge results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
Default task for all agents |
required |
task_map
|
dict[int, str] | None
|
Optional mapping of agent index to custom task |
None
|
Source code in src/locus/agent/composition.py
LoopAgent ¶
Bases: BaseModel
Run an agent repeatedly until a condition is met.
The agent is called in a loop. After each iteration, the condition function is called with the latest output. If it returns True, the loop stops. A max_loops limit prevents infinite execution.
Example
loop = LoopAgent( ... agent=editor, ... condition=lambda output: "APPROVED" in output, ... max_loops=5, ... loop_prompt="Review and improve:\n{previous_output}\n\nSay APPROVED if quality is good.", ... ) result = await loop.run("Write a haiku about Python")
run
async
¶
Execute agent in a loop until condition is met or max_loops reached.
Source code in src/locus/agent/composition.py
Orchestrator + Specialists¶
Orchestrator ¶
Bases: BaseModel
Orchestrator for coordinating specialist agents.
Features: - Selects which specialists to invoke based on the task - Routes tasks to appropriate specialists - Correlates findings from multiple specialists - Summarizes results into a coherent response
register_specialist ¶
register_specialists ¶
execute
async
¶
Execute the orchestration workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task to process |
required |
context
|
dict[str, Any] | None
|
Optional additional context |
None
|
Returns:
| Type | Description |
|---|---|
OrchestratorResult
|
OrchestratorResult with summary and all findings |
Source code in src/locus/multiagent/orchestrator.py
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 | |
with_model ¶
Return a copy of this orchestrator with the given model.
Source code in src/locus/multiagent/orchestrator.py
RoutingDecision ¶
Bases: BaseModel
A decision made by the orchestrator.
create_orchestrator ¶
create_orchestrator(name: str = 'Orchestrator', specialists: list[Specialist] | None = None, model: Any = None) -> Orchestrator
Create an orchestrator with the given specialists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Orchestrator name |
'Orchestrator'
|
specialists
|
list[Specialist] | None
|
List of specialists to register |
None
|
model
|
Any
|
Model for decision making |
None
|
Returns:
| Type | Description |
|---|---|
Orchestrator
|
Configured Orchestrator instance |
Source code in src/locus/multiagent/orchestrator.py
Specialist ¶
Bases: BaseModel
A specialist agent focused on a specific domain.
Features: - Domain-specific system prompt - Focused tool set - Optional playbook integration - Confidence-based execution
select_playbook ¶
Select the most appropriate playbook for a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task description |
required |
Returns:
| Type | Description |
|---|---|
Playbook | None
|
Best matching playbook or None |
Source code in src/locus/multiagent/specialist.py
execute
async
¶
execute(task: str, context: dict[str, Any] | None = None, registry: ToolRegistry | None = None) -> SpecialistResult
Execute the specialist on a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task to perform |
required |
context
|
dict[str, Any] | None
|
Optional context from orchestrator or other specialists |
None
|
registry
|
ToolRegistry | None
|
Tool registry (uses self.tools if not provided) |
None
|
Returns:
| Type | Description |
|---|---|
SpecialistResult
|
SpecialistResult with output and confidence |
Source code in src/locus/multiagent/specialist.py
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 | |
with_model ¶
Swarm¶
Swarm ¶
Bases: BaseModel
A self-organizing swarm of agents.
Features: - Agents coordinate autonomously - Shared context/memory for communication - Dynamic task allocation based on capabilities - Parallel execution with coordination
add_agent ¶
Add an agent to the swarm.
If the swarm has a model configured and the incoming agent does
not, the agent inherits the swarm's model. Without this, the
agent's first work_on_task would fail with
"No model configured for agent" — which used to be the most
common silent-failure mode for new users of the swarm API.
Source code in src/locus/multiagent/swarm.py
add_task ¶
add_task(description: str, priority: int = 0, parent_task_id: str | None = None, metadata: dict[str, Any] | None = None) -> SwarmTask
Add a task to the queue.
Source code in src/locus/multiagent/swarm.py
execute
async
¶
Execute the swarm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
initial_task
|
str | None
|
Optional initial task to add |
None
|
decompose_tasks
|
bool
|
Whether to decompose tasks into subtasks |
True
|
Returns:
| Type | Description |
|---|---|
SwarmResult
|
SwarmResult with all completed work |
Source code in src/locus/multiagent/swarm.py
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 | |
with_model ¶
Return a copy with the given model for all agents.
Source code in src/locus/multiagent/swarm.py
SharedContext ¶
Bases: BaseModel
Shared context/memory for swarm agents.
All agents can read from and write to this shared state.
add_finding
async
¶
Add a finding to the shared context.
Source code in src/locus/multiagent/swarm.py
post_to_blackboard
async
¶
Post a message to the blackboard.
Source code in src/locus/multiagent/swarm.py
record_task_result
async
¶
get_summary ¶
Get a summary of the current context state.
Source code in src/locus/multiagent/swarm.py
SwarmAgent ¶
Bases: BaseModel
An agent in the swarm.
Autonomously claims and works on tasks from the shared queue.
can_handle ¶
Decide whether this agent is eligible to claim task.
Resolution order:
- Tag set-membership — if the task declares
required_tags, every required tag must appear in :attr:capabilities. This is the deterministic path — the swarm's primary discovery mechanism. - Generalist — if neither side declares anything,
the agent claims the task (
capabilities=[]⇒ generalist). - Substring fallback — kept for backwards compatibility with pre-tag swarms: if the agent has capabilities but the task has no tags, match keywords against the description.
Source code in src/locus/multiagent/swarm.py
priority_for_task ¶
Score this agent's fit for task in the range [0, 1].
Tag-driven scoring (when the task declares tags):
- Each required tag the agent advertises adds 1.0 weight.
- Each preferred tag the agent advertises adds 0.5 weight.
- Score = (sum of weights) / (max possible weights), clamped.
Falls through to the legacy substring score for tag-less tasks so pre-tag swarms keep their old behaviour.
Source code in src/locus/multiagent/swarm.py
work_on_task
async
¶
Work on a task using the shared context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
SwarmTask
|
The task to work on |
required |
context
|
SharedContext
|
Shared context with other agents |
required |
Returns:
| Type | Description |
|---|---|
tuple[str | None, str | None]
|
Tuple of (result, error) |
Source code in src/locus/multiagent/swarm.py
SwarmTask ¶
Bases: BaseModel
A task in the swarm task queue.
required_tags declares the capability tags an agent must
advertise to claim this task — set-membership against
:attr:SwarmAgent.capabilities. Empty means any agent may claim
it; preferred_tags boost an agent's priority score without
being a hard requirement.
Backwards-compat: agents that pre-date this change still work —
if no tags are set, the prior substring-match path runs as a
fallback (see SwarmAgent.can_handle).
SwarmResult ¶
Bases: BaseModel
Result from swarm execution.
Handoff¶
Handoff ¶
Bases: BaseModel
Manages handoffs between agents.
Features: - Context transfer between agents - State preservation - Handoff event emission - Chain of custody tracking
register_agent ¶
register_agents ¶
create_handoff
async
¶
create_handoff(source_agent: HandoffAgent, target_agent_id: str, task: str, reason: HandoffReason, state: AgentState | None = None, findings: dict[str, Any] | None = None, instructions: str | None = None) -> HandoffContext
Create a handoff context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_agent
|
HandoffAgent
|
The agent initiating the handoff |
required |
target_agent_id
|
str
|
ID of the target agent |
required |
task
|
str
|
The original task |
required |
reason
|
HandoffReason
|
Reason for the handoff |
required |
state
|
AgentState | None
|
Current agent state |
None
|
findings
|
dict[str, Any] | None
|
Findings to transfer |
None
|
instructions
|
str | None
|
Specific instructions for target |
None
|
Returns:
| Type | Description |
|---|---|
HandoffContext
|
HandoffContext for the target agent |
Source code in src/locus/multiagent/handoff.py
execute_handoff
async
¶
execute_handoff(source_agent: HandoffAgent, target_agent_id: str, task: str, reason: HandoffReason, state: AgentState | None = None, findings: dict[str, Any] | None = None, instructions: str | None = None) -> HandoffResult
Execute a complete handoff.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_agent
|
HandoffAgent
|
The agent initiating the handoff |
required |
target_agent_id
|
str
|
ID of the target agent |
required |
task
|
str
|
The original task |
required |
reason
|
HandoffReason
|
Reason for the handoff |
required |
state
|
AgentState | None
|
Current agent state |
None
|
findings
|
dict[str, Any] | None
|
Findings to transfer |
None
|
instructions
|
str | None
|
Specific instructions for target |
None
|
Returns:
| Type | Description |
|---|---|
HandoffResult
|
HandoffResult from the target agent |
Source code in src/locus/multiagent/handoff.py
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 | |
chain_handoff
async
¶
chain_handoff(agent_chain: list[str], task: str, initial_state: AgentState | None = None) -> list[HandoffResult]
Execute a chain of handoffs through multiple agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_chain
|
list[str]
|
List of agent IDs to process through |
required |
task
|
str
|
The task to process |
required |
initial_state
|
AgentState | None
|
Initial state |
None
|
Returns:
| Type | Description |
|---|---|
list[HandoffResult]
|
List of results from each handoff |
Source code in src/locus/multiagent/handoff.py
HandoffContext ¶
Bases: BaseModel
Context transferred during a handoff.
Contains all information needed for the target agent to continue.
to_prompt ¶
Convert handoff context to a prompt for the target agent.
Source code in src/locus/multiagent/handoff.py
HandoffReason ¶
Bases: StrEnum
Reason for a handoff between agents.
create_handoff_agent ¶
create_handoff_agent(name: str, description: str = '', system_prompt: str = '', tools: list[Tool] | None = None, model: Any = None) -> HandoffAgent
Create a handoff-capable agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Agent name |
required |
description
|
str
|
Agent description |
''
|
system_prompt
|
str
|
System prompt |
''
|
tools
|
list[Tool] | None
|
Available tools |
None
|
model
|
Any
|
Model for the agent |
None
|
Returns:
| Type | Description |
|---|---|
HandoffAgent
|
Configured HandoffAgent |
Source code in src/locus/multiagent/handoff.py
create_handoff_manager ¶
Create a handoff manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agents
|
list[HandoffAgent] | None
|
Agents to register |
None
|
max_chain
|
int
|
Maximum handoff chain length |
5
|
Returns:
| Type | Description |
|---|---|
Handoff
|
Configured Handoff manager |
Source code in src/locus/multiagent/handoff.py
StateGraph¶
StateGraph ¶
Bases: BaseModel
A stateful graph for workflow execution.
Supports: - Conditional edges with dynamic routing - Cycles (optional, with max iteration limit) - Human-in-the-loop interrupts - Map-reduce via Send - Subgraph composition - State reducers for composable updates
model_post_init ¶
Initialize after model creation.
Source code in src/locus/multiagent/graph.py
set_entry_point ¶
Set the entry point node (after START).
Source code in src/locus/multiagent/graph.py
set_finish_point ¶
Set a finish point node (before END).
add_node ¶
add_node(node_id: str | Node, executor: Callable[..., Any] | StateGraph | None = None, *, description: str = '', condition: Callable[[dict[str, Any]], bool] | None = None, max_retries: int = 0, timeout_ms: float | None = None, retry_policy: RetryPolicy | None = None, cache_policy: CachePolicy | None = None, defer: bool = False) -> StateGraph
Add a node to the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_id
|
str | Node
|
Unique identifier for the node, or a Node object (for backward compatibility) |
required |
executor
|
Callable[..., Any] | StateGraph | None
|
Function or subgraph to execute (optional if node_id is a Node) |
None
|
description
|
str
|
Node description |
''
|
condition
|
Callable[[dict[str, Any]], bool] | None
|
Optional condition for execution |
None
|
max_retries
|
int
|
Retry attempts on failure |
0
|
timeout_ms
|
float | None
|
Execution timeout |
None
|
Returns:
| Type | Description |
|---|---|
StateGraph
|
Self for chaining |
Source code in src/locus/multiagent/graph.py
add_edge ¶
add_edge(source: str | Node, target: str | Node, key_mapping: dict[str, str] | None = None, transform: Callable[[Any], Any] | None = None) -> StateGraph
Add a directed edge between nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Node
|
Source node ID or Node object |
required |
target
|
str | Node
|
Target node ID or Node object |
required |
key_mapping
|
dict[str, str] | None
|
Optional key mapping for data transformation |
None
|
transform
|
Callable[[Any], Any] | None
|
Optional transform function |
None
|
Returns:
| Type | Description |
|---|---|
StateGraph
|
Self for chaining |
Source code in src/locus/multiagent/graph.py
add_conditional_edges ¶
add_conditional_edges(source: str, router: Callable[[dict[str, Any]], str | list[str]], targets: dict[str, str] | None = None, default: str | None = None) -> StateGraph
Add conditional edges with dynamic routing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Source node ID |
required |
router
|
Callable[[dict[str, Any]], str | list[str]]
|
Function that returns target node ID(s) based on state |
required |
targets
|
dict[str, str] | None
|
Optional mapping from router return values to node IDs |
None
|
default
|
str | None
|
Default target if router returns unmapped value |
None
|
Returns:
| Type | Description |
|---|---|
StateGraph
|
Self for chaining |
Example
def route_by_type(state): return "error" if state["has_error"] else "success"
graph.add_conditional_edges("check", route_by_type, { "error": "handle_error", "success": "continue" })
Source code in src/locus/multiagent/graph.py
execute
async
¶
execute(inputs: dict[str, Any] | Command | None = None, *, config: GraphConfig | None = None, _event_sink: Any = None) -> GraphResult
Execute the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
dict[str, Any] | Command | None
|
Initial state or Command (for resume) |
None
|
config
|
GraphConfig | None
|
Optional execution configuration |
None
|
_event_sink
|
Any
|
Internal-use only. When provided, an async callable
|
None
|
Returns:
| Type | Description |
|---|---|
GraphResult
|
GraphResult with final state and outputs |
Source code in src/locus/multiagent/graph.py
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 | |
stream
async
¶
stream(inputs: dict[str, Any] | Command | None = None, *, config: GraphConfig | None = None, mode: StreamMode | None = None) -> AsyncIterator[StreamEvent]
Stream graph execution events as nodes complete.
Drives :meth:execute on a background task with an async-queue
sink wired in, then yields each node-completion event in real time
(instead of collecting them at the end). The final state arrives as
the last yielded event in VALUES mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
dict[str, Any] | Command | None
|
Initial state or Command (for resume). |
None
|
config
|
GraphConfig | None
|
Execution configuration. |
None
|
mode
|
StreamMode | None
|
Stream mode override ( |
None
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[StreamEvent]
|
|
AsyncIterator[StreamEvent]
|
the final state when |
AsyncIterator[StreamEvent]
|
exception the underlying execute raised so callers can react. |
Source code in src/locus/multiagent/graph.py
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 | |
ainvoke
async
¶
ainvoke(inputs: dict[str, Any] | None = None, config: GraphConfig | None = None, **kwargs: Any) -> dict[str, Any]
LangChain/LangGraph-compatible alias for execute() returning final_state.
Source code in src/locus/multiagent/graph.py
astream
async
¶
astream(inputs: dict[str, Any] | None = None, config: GraphConfig | None = None, **kwargs: Any) -> AsyncIterator[StreamEvent]
LangChain/LangGraph-compatible alias for stream().
Source code in src/locus/multiagent/graph.py
get_graph ¶
aget_state
async
¶
compile ¶
compile(*, checkpointer: Any | None = None, interrupt_before: list[str] | None = None, interrupt_after: list[str] | None = None, store: Any | None = None) -> StateGraph
Compile the graph with configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpointer
|
Any | None
|
Checkpointer for state persistence |
None
|
interrupt_before
|
list[str] | None
|
Nodes to pause before |
None
|
interrupt_after
|
list[str] | None
|
Nodes to pause after |
None
|
store
|
Any | None
|
Store for cross-thread memory |
None
|
Returns:
| Type | Description |
|---|---|
StateGraph
|
Configured graph (self) |
Source code in src/locus/multiagent/graph.py
GraphConfig ¶
Bases: BaseModel
Configuration for graph execution.
Functional API¶
task ¶
task(fn: Callable | None = None, *, name: str | None = None, retry_attempts: int = 1, cache: bool = False) -> Any
Decorator that marks a function as a parallelizable task.
Tasks are tracked within an entrypoint for monitoring and can be configured with retry and caching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable | None
|
The function to decorate. |
None
|
name
|
str | None
|
Task name (defaults to function name). |
None
|
retry_attempts
|
int
|
Number of retry attempts on failure. |
1
|
cache
|
bool
|
If True, cache results for identical arguments. |
False
|
Example
@task async def fetch(url: str) -> dict: return await httpx.get(url).json()
@task(retry_attempts=3) async def unreliable_api(query: str) -> str: return await call_api(query)
Source code in src/locus/multiagent/functional.py
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 | |
entrypoint ¶
Decorator that marks a function as a workflow entrypoint.
The entrypoint is the top-level function that orchestrates tasks. It tracks all task executions and returns an EntrypointResult.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable | None
|
The function to decorate. |
None
|
name
|
str | None
|
Entrypoint name (defaults to function name). |
None
|
Example
@entrypoint async def my_workflow(input_data: str) -> str: step1 = await fetch(input_data) step2 = await process(step1) return step2
result = await my_workflow("hello")
result is the raw return value¶
Access metadata via my_workflow.last_result¶
Source code in src/locus/multiagent/functional.py
A2A protocol¶
A2AServer ¶
A2AServer(agent: Any, name: str = 'Locus Agent', description: str = '', skills: list[AgentSkill] | list[str] | None = None, url: str = '', provider: AgentProvider | None = None, version: str = '0.1.0', api_key: str | None = None, allow_unauthenticated: bool = False)
Expose a Locus Agent as a spec-compliant A2A endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
Any
|
A Locus |
required |
name
|
str
|
Display name for the Agent Card. |
'Locus Agent'
|
description
|
str
|
One-line description for the Agent Card. |
''
|
skills
|
list[AgentSkill] | list[str] | None
|
List of :class: |
None
|
url
|
str
|
Public URL the agent is reachable at — set this for
cross-process / cross-host deployments so the card's |
''
|
provider
|
AgentProvider | None
|
Optional :class: |
None
|
version
|
str
|
Agent semver — useful for capability negotiation. |
'0.1.0'
|
api_key
|
str | None
|
Bearer token required on every route; if |
None
|
allow_unauthenticated
|
bool
|
Bind to non-loopback without a key. Use only behind an upstream proxy that terminates auth. |
False
|
Example::
from locus import Agent
from locus.a2a import A2AServer
from locus.a2a.spec import AgentSkill
server = A2AServer(
agent=my_agent,
name="Research Agent",
description="Open-web research with citations.",
skills=[
AgentSkill(
id="research",
name="Research",
description="Answer with cited sources.",
tags=["search", "summarise"],
),
],
url="https://research.example.com",
api_key="secret",
)
server.run(port=8001)
Source code in src/locus/a2a/protocol.py
run ¶
Run the A2A server.
Defaults to loopback binding. Non-loopback bindings require
either api_key to be set or allow_unauthenticated=True.
Source code in src/locus/a2a/protocol.py
A2AClient ¶
Call a remote A2A agent from Locus.
Spec-compliant methods:
- :meth:
get_agent_card— fetches/.well-known/agent-card.json, falling back to the legacy/agent-cardendpoint. - :meth:
send_message— JSON-RPCmessage/send; returns a :class:Taskyou can poll with :meth:get_task. - :meth:
send_message_streaming— JSON-RPCmessage/stream; yields events from the SSE stream. - :meth:
get_task, :meth:cancel_task— task lifecycle.
Plus the legacy convenience APIs preserved from the pre-spec implementation:
- :meth:
invoke— flat string-in / string-out over/a2a/invoke. - :meth:
as_tool— wrap a remote agent as a Locus@tool.
Source code in src/locus/a2a/protocol.py
get_agent_card
async
¶
Fetch the remote agent's capability card.
Tries the spec well-known URL first, falls back to the legacy
/agent-card endpoint for older peers.
Source code in src/locus/a2a/protocol.py
send_message
async
¶
Send a message via JSON-RPC message/send and return the Task.
Source code in src/locus/a2a/protocol.py
send_message_streaming
async
¶
Send a message via JSON-RPC message/stream and yield events.
Source code in src/locus/a2a/protocol.py
get_task
async
¶
Fetch a task by id (JSON-RPC tasks/get).
Source code in src/locus/a2a/protocol.py
cancel_task
async
¶
invoke
async
¶
Send a flat text prompt over the legacy /a2a/invoke.
Useful when you control both ends of the wire and want a one-line
round-trip; spec-compliant peers should prefer
:meth:send_message so they can read the full :class:Task.
Source code in src/locus/a2a/protocol.py
as_tool ¶
Wrap this remote agent as a Locus @tool.