In Lesson 6.3, our Research Coordinator Agent selected specialist agents as tools. The model could decide whether to use Discovery, Evidence, or Synthesis for a particular request.
That flexibility introduces a practical question: what happens if a specialist returns incomplete information, a result is missing, or a tool fails? A coordinator can explain what went wrong, but some safeguards should work even when the coordinator makes a poor decision.
In this lesson, we introduce hybrid orchestration and use application-maintained state and validation to handle these situations.
Why we are choosing hybrid orchestration
This is a deliberate architectural decision for two reasons.
First, our course is examining different methods of orchestration. Lesson 6.1 used code-driven orchestration, Lesson 6.2 combined fixed sequencing with specialist output contracts, and Lesson 6.3 allowed a model-driven coordinator to choose agent-tools. Hybrid orchestration lets us explore a different allocation of responsibility: model judgment for delegation and application code for rules that must be enforced.
Second, our research project’s requirements have changed. We now need to carry information across agent calls, check intermediate results, and respond predictably when research inputs or specialist calls are incomplete. Those requirements should not depend exclusively on instructions to the Coordinator Agent.
Our decision: the Coordinator continues choosing specialists; Python owns the shared workflow state and controls whether a research conclusion is accepted. Hybrid is not automatically better for every project. It is a reasonable fit for these requirements.
Three concepts that are easy to confuse
Structured output defines the shape of a specialist’s result. A Pydantic model can require source IDs, an assessment, and a list of limitations. It cannot independently establish whether those sources are real or whether the assessment is correct.
Shared workflow state records what actually happened in the application: which sources were discovered, whether evidence was evaluated, errors encountered, and whether a summary was prepared. In our lab, this is a Python WorkflowState object, separate from the Coordinator’s conversational context.
Application-level validation decides whether state meets specific rules before proceeding. For example, our demonstration requires both fictional research records before publishing its predefined summary. A plausible model-generated response does not bypass this check.
The distinction matters: a well-formed response may still be incomplete, and a coordinator may produce fluent prose even though its evidence tool failed.
How the hybrid workflow operates
The Python application starts the Research Coordinator Agent and exposes three callable tools. discover_sources invokes the Discovery Agent and records returned source IDs. evaluate_evidence invokes the Evidence Agent and saves its structured assessment, but it blocks the request when discovery has not been recorded. The third tool keeps its Lesson 6.3 name, synthesize_findings, but here it is Python application code, not the Synthesis Agent. It consults a code-enforced validation gate and only returns a predefined, qualified summary if the gate passes.
The Coordinator still decides whether to call synthesize_findings. Python decides whether that call passes validation and produces a summary. After the Coordinator completes its run, Python validates the state again and displays the summary only if the gate passes and a synthesis was actually recorded. The script labels this result Approved output. In this lesson, that means accepted by the validation gate, not approved by a person; human approval arrives in Lesson 6.5. The Coordinator’s final conversational response is displayed for observation, but it is not automatically accepted as the research result.
The Coordinator may choose tools differently from the instructions. This is why the final application-level check matters. We are not claiming that the model will always call the expected tools. Tool wrappers record observable invocation, return, state-update, and validation events; these events are not a record of the model’s private reasoning.

Hands-on lab
Use the shared Module 6 lab. It contains two separately runnable Python files for Lesson 6.4:
lab6_4_01_shared_context.pylab6_4_02_failure_handling.py
Run Experiment 01 first, followed by Experiment 02. Each experiment runs independently.
Use Python 3.12+ and an API key. These exercises use fictional notes rather than external research. Neither experiment stores findings or calls MCP.
Experiment 01: Shared context
Run:
python lab6_4_01_shared_context.py
The Coordinator is asked to prepare a cautious summary of two fictional research records: a single-team time comparison (15 days before, 5 days after) and three informal interviews. The Discovery and Evidence specialists return structured output. Python stores their results in a single workflow state object.
Read the numbered observable execution trace first. It records when the Coordinator actually invokes a tool, when a specialist result returns, when Python saves the result to shared state, and when the validation gate runs. It does not reveal the model’s internal deliberation.
Then examine the printed state and application decision. Did the state contain both records and a preliminary evidence assessment? Was synthesize_findings invoked and permitted to run? If the gate passed and a synthesis was recorded, notice the qualified nature of the accepted output: the figures are illustrative, with no control group or measured quality. If the Coordinator skipped required calls, the gate should block the output. A PASS does not establish that the fictional evidence is factual or causally reliable.
Experiment 02: Failure handling
Run:
python lab6_4_02_failure_handling.py
This independent scenario begins with a fictional report of a five-day prototype, but without a baseline for comparison. In this experiment, the Evidence step cannot succeed. If evaluate_evidence runs after a source is recorded, it raises and catches a simulated service failure. Python records the failed step and returns a failure message to the Coordinator without crashing the lab.
Compare the numbered trace with Experiment 01. Which outcome you see depends on which tools the Coordinator calls, and in what order:
| Recorded state | How it typically happens | Final validation reason |
|---|---|---|
Sources recorded, evidence_status: "failed", one error |
Discovery recorded demo-003, then the Coordinator called evaluate_evidence |
Evidence step is failed, not complete |
No sources recorded, errors empty |
Discovery didn’t run or returned no known source; any Evidence call was blocked | No sources were recorded |
Sources recorded, evidence_status: "not_started", errors empty |
The Coordinator never called evaluate_evidence |
Evidence step is not_started, not complete |
Every outcome ends in a safe stop: Validation: BLOCK and Approved output: BLOCKED (safe stop). Because the Evidence step can never complete, this experiment always ends in a blocked result. If the Coordinator calls synthesize_findings, the gate blocks it for the same reason. The missing baseline would also block the claim, but you won’t see that reason in this experiment because the Evidence check fails first. An empty errors list does not mean validation passed.
We did not implement automatic retries. A real system would need retry limits, error categorization, and a decision about when to request human review. For this lab, we deliberately keep the failure visible.
What did you learn?
Model-driven coordination and code-enforced safeguards can coexist. The Coordinator selects actions; the application maintains state and enforces validation rules. Structured output helps with reliable data transfer, while validation addresses requirements that a schema alone cannot guarantee.
The trace demonstrates observable tool and Python events, not the Coordinator’s private reasoning. Missing evidence, validation rejection, and a caught execution error are distinct conditions even when they all lead to a blocked result.
Test Your Understanding
Question 1 of 3
Why did we choose hybrid orchestration for Lesson 6.4?