Repository navigation
Agentic Patterns Compound Lab · Choosing and wiring seven patterns #35
akash-coded
started this conversation in
Hands-on Labs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Compound Exercise: Choosing and Wiring Agentic Patterns
Language: Python 3.11+ | Topics: Prompt chaining, augmented LLM (tools), routing, parallelisation, orchestrator-workers, evaluator-optimizer, agent graphs, swarms, composition | Level: Intermediate to Advanced
0. Setup
0.1 Install and credentials
Colab:
!pip install -q "strands-agents==1.42.0" boto3 pydantic, then set the three env vars in a cell, then run.0.2 Shared file:
pierpoint_common.pyEvery later snippet imports from this. Create it once.
Run
python pierpoint_common.pybefore anything else. TwoREADYlines means you are clear to proceed.0.3 Ground rules for this exercise
PARK.CHEAP_MODEL. Nodes that judge, write, or plan getREASONING_MODEL. You will be asked to justify each choice.TODOs are filled. No pseudocode.structured_outputmisbehaves on Nova Lite, switch that one call toREASONING_MODELand note it in your answer.1. The scenario: PierPoint Terminal Ops Copilot
PierPoint runs a container terminal. One inbound channel (email plus a web form) carries every kind of request from every kind of counterparty. Today an ops team of nine reads all of it and decides what happens next. You are designing the copilot that sits in front of that team.
Hard constraints from the ops manager:
2. The Control Question Ladder
Before any pattern name, four questions. Answer them in order and the pattern mostly picks itself.
flowchart TD Q0{"Q0 One flow fits all inbound?"} Q0 -->|No| ROUTER["Router at the front door"] Q0 -->|Yes| Q1 ROUTER --> Q1{"Q1 Path known before runtime?"} Q1 -->|Yes| Q3{"Q3 How many independent sub-answers?"} Q1 -->|No| Q2{"Q2 Who picks the next step?"} Q3 -->|One| CHAIN["Prompt chain with gates"] Q3 -->|Many| PAR["Parallel sectioning plus code reducer"] Q2 -->|Code on node results| GRAPH["Agent graph, conditional edges"] Q2 -->|One lead LLM| ORCH["Orchestrator-workers or agents-as-tools"] Q2 -->|Peer agents| SWARM["Swarm with handoff"] CHAIN --> Q4{"Q4 Wrong answer cheap to undo?"} PAR --> Q4 GRAPH --> Q4 ORCH --> Q4 SWARM --> Q4 Q4 -->|Yes| SHIP["Ship the pattern as is"] Q4 -->|No| GATE["Add deterministic gate plus human approver"]Pattern cards
Task 1: Match symptom to pattern
Write one pattern name per row. One pattern is used twice. One row is a trap: the honest answer is "no agent needed".
Task map
S1. Front door: one channel, five kinds of work
Six real inbound items:
Task 2: Fill the front door decision tree
Replace
?Athrough?Ewith concrete labels.?Aand?Bare the two checks that run before any model call.?Cis the model tier.?Dand?Eare the two exits.flowchart TD IN["Inbound item"] --> A{"?A"} A -->|hit| LANE1["Dispatch to lane, confidence 1.0"] A -->|miss| B{"?B"} B -->|too short or empty| E1["?D"] B -->|ok| C["Classifier on ?C"] C --> CONF{"Confidence above threshold?"} CONF -->|yes| LANE2["Dispatch to predicted lane"] CONF -->|no| E2["?E"]Task 3: Trade-off table, front door options
Row 1 is filled as a worked pass. Fill rows 2 and 3, then circle one verdict.
Task 4: Code the hybrid router
Correct run looks like:
gate_passhumaneta_querydamage_claimcongestionhumanTwo of six items cost zero tokens. Note that number, you will need it in T16.
S2. DG gate pass: fixed steps, unforgiving output
A dangerous goods gate pass has the same three steps every time: pull the fields out of free text, check them against written rules, draft the pass. A wrong pass is a regulatory incident.
Task 5: Order the chain and place the gate
These five cards are shuffled. Write the correct order, then mark with
[GATE]the one step that must be pure Python with no model in it, and mark with[STOP]the step after which an invalid request must exit without ever reaching the drafter.Task 6: Code the chain with a hard gate
Correct run looks like: first call prints a six line pass ending in
APPROVER: ____. Second call prints a rejection naming three failures (container shape, UN shape, IMO class) and makes exactly one model call, not two.S3. ETA answers: the model needs facts it does not have
Task 7: Design the tool contract before writing it
Fill the table. The failure column is the one people skip and it is the one that decides whether the agent lies.
berth_etayard_slotTask 8: Code the augmented agent
Correct run looks like: question 3 produces an explicit "no record" answer. Question 4 is the interesting one. Write down in one line what the agent did with it and whether that behaviour is acceptable.
S4. Pre-arrival sweep: four checks that do not know about each other
Before a vessel berths, four checks run: customs holds, crane availability, weather window, document completeness. They share no data. Ops wants one verdict.
Task 9: Parallel or sequential
Mark each with
PorSand give a one-line reason. Only two of these four earn parallelism.Task 10: Code the sweep
Correct run looks like: four lines, then a verdict of BLOCKED naming customs and documents. Weather is a trap, 28 knots is inside the 32 knot limit.
Task 11: Debug this
A colleague wrote the version below. It crashes.
Answer three things:
Agent(..., concurrent_invocation_mode=ConcurrentInvocationMode.UNSAFE_REENTRANT)instead. Say in one sentence why that is the wrong fix here even though it stops the crash.S5. Damage claim narrative: quality needs a judge
A damage claim response goes to a cargo owner and may be read by an insurer. Requirements: name the container, state observed damage, state the next step, never admit liability, stay under 120 words.
Task 12: Trace the loop
This graph is wired as:
drafter -> reviewer,reviewer -> reviserwhen the review contains REVISE,reviser -> reviewer,reviewer -> publisherwhen the review contains APPROVE. Entry point isdrafter. Limits arereset_on_revisit(True)andset_max_node_executions(N).Fill both rows.
execution_countcompleted_nodesTask 13: Code the evaluator-optimizer graph
Correct run looks like: order starts
['drafter', 'reviewer', ...]. Either the reviewer approves the first draft, or you see one or morereviser, reviewerpairs. If your run never approves, that is a finding, not a bug: record what the reviewer kept rejecting.S6. Congestion incident: nobody knows the path in advance
Gate 3 is at 90 minutes. Depending on what the cause turns out to be, this needs yard planning, or customs, or line comms, or two of them, or all three, and the order is not knowable up front.
Task 14: Trade-off table, three candidate patterns
Then answer: PierPoint's constraint table says ops must reconstruct which step produced which claim. Which option does that constraint eliminate, and what would you have to add to bring it back?
Task 15: Code the swarm, then the alternative
Then the alternative, same incident:
Run both. Write down the
node_historyfrom the swarm and the tool call order from the lead. One line: which one would you hand to an oncall engineer at 3am, and why.S7. Assembly
Task 16: Fix the architecture, then defend it
The diagram below is the proposed end state. It contains four defects. Find them, say what each one costs at PierPoint specifically, and redraw the corrected version.
flowchart TD IN["Inbound item"] --> CLS["LLM classifier"] IN --> DG["DG gate pass chain"] CLS --> ETA["ETA agent with tools"] CLS --> CLAIM["Claim graph, drafter reviewer reviser"] CLS --> SW["Congestion swarm"] DG --> ISSUE["Issue gate pass"] ISSUE --> VAL["Validate container and UN and IMO"] SW --> CLS CLAIM --> SEND["Send to cargo owner"] ETA --> SEND subgraph SWEEP [Pre arrival sweep] P1["customs"] --> MERGE["LLM merges the four verdicts"] P2["cranes"] --> MERGE P3["weather"] --> MERGE P4["documents"] --> MERGE endThen finish these three:
assert result.execution_count <= N.Submission checklist
[GATE]and[STOP]markss1_router.py,s2_chain.py,s3_tools.py,s4_parallel.py,s5_graph.py,s6_swarm.pynode_historyand lead tool call order, plus the 3am answerAll reactions