()
| 29 | |
| 30 | |
| 31 | def main() -> int: |
| 32 | config = str(repo_config_path()) |
| 33 | agent = Agent.create(config) |
| 34 | session = agent.session(".", SessionOptions()) |
| 35 | |
| 36 | # 1. parallel — fan out independent steps; outcomes come back in order. |
| 37 | outcomes = session.parallel( |
| 38 | [ |
| 39 | { |
| 40 | "task_id": "langs", |
| 41 | "agent": "general", |
| 42 | "description": "list languages", |
| 43 | "prompt": "Name three systems programming languages, comma-separated.", |
| 44 | "max_steps": 2, |
| 45 | }, |
| 46 | { |
| 47 | "task_id": "verdict", |
| 48 | "agent": "general", |
| 49 | "description": "classify", |
| 50 | "prompt": "Is Rust memory-safe without a GC? Answer yes or no.", |
| 51 | "max_steps": 2, |
| 52 | # Schema-validated structured output for this step. |
| 53 | "output_schema": { |
| 54 | "type": "object", |
| 55 | "properties": {"memory_safe": {"type": "boolean"}}, |
| 56 | "required": ["memory_safe"], |
| 57 | }, |
| 58 | }, |
| 59 | ] |
| 60 | ) |
| 61 | for o in outcomes: |
| 62 | print(f"[parallel] {o['task_id']}: success={o['success']} structured={o.get('structured')}") |
| 63 | |
| 64 | # 2. pipeline — each item chains through stages; stage 2 builds on stage 1. |
| 65 | # Return None from a stage (or raise — caught and treated as None) to |
| 66 | # stop that item's chain. |
| 67 | results = session.pipeline( |
| 68 | ["the Rust programming language"], |
| 69 | [ |
| 70 | lambda ctx: { |
| 71 | "task_id": "summarize", |
| 72 | "agent": "general", |
| 73 | "description": "summarize", |
| 74 | "prompt": f"In one sentence, what is {ctx['item']}?", |
| 75 | "max_steps": 2, |
| 76 | }, |
| 77 | lambda ctx: { |
| 78 | "task_id": "classify", |
| 79 | "agent": "general", |
| 80 | "description": "classify", |
| 81 | "prompt": "Reply with one word YES or NO: does this describe a " |
| 82 | f"programming language?\n\n{ctx['previous']['output']}", |
| 83 | "max_steps": 2, |
| 84 | }, |
| 85 | ], |
| 86 | ) |
| 87 | for r in results: |
| 88 | print(f"[pipeline] final={None if r is None else r['output'][:60]!r}") |
no test coverage detected