# Advanced AI Agents: Research, Delegation, and Event-Driven Workflows

**Harness Engineering · Module 8 of 16**

> **Start here:** understand bounded tools and saved state. No multi-agent service is required.
>
> **Your goal:** design long-running work whose evidence, ownership, and stopping conditions remain clear.

A support question may need one policy lookup. A research brief can need several sources, conflicting findings, intermediate files, and a reviewer. The larger task needs more structure, but that does not automatically mean it needs more agents.

Begin with deliverables and evidence. Add delegation only where subtasks can proceed independently and their outputs can be reconciled. Add unattended triggers only where event validation and duplicate handling are understood.

![A scoped brief splits into independent evidence tasks, reconciles into a reviewed draft, and records unresolved gaps.](https://cdn.hashnode.com/uploads/covers/5fb3b801b589f1618af9d143/8cd7b449-c729-49e1-9050-4b5106edb77e.png)

*Parallel work produces inputs to a decision. It does not distribute away responsibility for that decision.*

## 1. Define a research stopping rule

Use this question: “Which approach should our fictional shop pilot for policy-answer drafting: prompt-only, retrieval, or a decision table?” Compare evidence-supported answers, maintenance effort, and review burden.

The supplied research cards are synthetic:

| Card | Reported example result | Limitation |
|---|---|---|
| A: prompt-only | 7/10 answers correct | No source display |
| B: retrieval | 9/10 correct | Two citation locations incorrect |
| C: decision table | 8/10 correct | Only five rules covered |

These are invented observations for learning, not benchmark results. A brief that simply declares B the winner misses citation trust and task coverage. State the decision criteria before comparing the cards.

Stop when material claims have support, important contradictions have been examined, and remaining unknowns are explicit. If the budget ends first, return a partial report. Search count is not a quality metric.

## 2. Use a visible workspace

Keep `brief.md`, `plan.md`, `sources.md`, `claims.md`, `draft.md`, and `review.md`. The active context can hold the current objective and unresolved questions; the workspace holds details that can be retrieved.

A plan records steps and expected artifacts. Revise it when evidence changes. A source ledger records what was actually consulted, its date and location, and the claims it supports. Preserve conflicting definitions instead of compressing them into a false consensus.

The execution environment matters. An in-memory file dictionary, a persistent filesystem, and a sandbox with a shell provide very different capabilities. A research task rarely needs permission to modify the original source files. Give it a separate draft workspace and narrow tools.

## 3. Delegate with contracts

Two useful assignments might be:

| Assignment | Inputs | Output | Boundary |
|---|---|---|---|
| Evidence quality | Cards A–C and scoring criteria | Claim table with support and gaps | Do not invent external findings |
| Operational fit | Same cards and fictional five-rule scope | Maintenance and coverage assessment | Internal recommendation only |

Each worker needs a precise task, permitted sources and tools, output format, budget, and obstacle-reporting rule. Avoid giving several workers the same broad goal and shared editable files. A supervisor must compare assumptions, remove duplicate findings, and resolve disagreements.

A delegated conclusion is not independent confirmation if all workers rely on the same flawed source. More model votes do not create missing evidence. In our example, no worker can infer production reliability from ten invented cases.

## 4. Treat ambient agents as event-driven applications

An ambient agent responds to an event: a message, document change, or schedule. Because the user may not be watching, validate the event, identify the caller and source, choose a route, and retain a durable processing record.

For a synthetic email assistant, routes are `ignore`, `notify`, and `draft_for_review`. Sending is outside this exercise.

```python
def route(event):
    if event["kind"] == "promotion":
        return "ignore"
    if event.get("requires_decision") or not event.get("has_policy"):
        return "notify"
    return "draft_for_review"


assert route({"kind": "promotion"}) == "ignore"
assert route({"kind": "question", "has_policy": False}) == "notify"
assert route({"kind": "question", "has_policy": True}) == "draft_for_review"
assert route({"kind": "question", "has_policy": True,
              "requires_decision": True}) == "notify"
print("4 routing checks passed")
```

The block was executed locally. It is a deterministic router over supplied labels, not a language-model classifier. A real inbox needs classification evaluation, sender validation, concurrency handling, and durable deduplication.

## 5. Prevent duplicate work without losing failed work

Store event identity, status, task identity, draft identity, and completion receipt. Check whether an event is already complete before creating another draft. A single in-memory set is insufficient across workers or restarts; production deduplication needs atomic ownership and durable state.

Be careful when marking an event processed. Marking it before draft creation can lose work after a crash. Marking it only afterward can create duplicate drafts if completion becomes ambiguous. Use stable operation identities, supported idempotency mechanisms, and reconciliation.

Schedules need a useful notification rule. “Check for material policy changes and notify on a difference” is more actionable than posting an unchanged report every hour. Record what changed and why the alert matters.

## 6. Scope feedback before storing it

“Make my drafts shorter” is a user preference. “This policy has changed” needs an authoritative source and version. “Escalate this unusual case” may be a one-time instruction. Keep those scopes separate in memory and routing updates.

An automated improvement process can propose a fix and evaluate it. It does not thereby authorize release. Keep baseline, candidate change, held-out cases, reviewer decision, and rollback criteria together.

## 7. Follow along

Write a one-page brief from the three research cards with a claim ledger and one unresolved question. Simulate one worker returning insufficient evidence. Revise the plan instead of manufacturing a successful result.

Then route six synthetic events, including a duplicate, missing policy, promotional message, and decision requiring a human. **Expected behavior:** no customer message is sent, duplicate completion is recognized, uncertain cases notify a reviewer, and each draft retains its event and source IDs.

## Further reading

- [Deep Agents overview](https://docs.langchain.com/oss/python/deepagents/overview) — planning, environment, and delegation.
- [Deep Research course](https://academy.langchain.com/courses/deep-research-with-langgraph) — research project context.
- [Ambient Agents course](https://academy.langchain.com/courses/ambient-agents) — event-driven project context.

## Next module

**Evaluate and observe agents:** inspect trajectories, compare versions, and separate quality from attractive output.

