Pegas field notes · October 2026
From One Model Call to a Multi-Agent System: How Pegas Learned to Route Work
How we turned a self-hosted Qwen3 4B deployment into a visible Request Desk with specialized agents, conditional privacy review, bounded correction loops, and inspectable handoffs.
A few days ago, Pegas was mainly a proof that we could run an open-weight model on our own cloud GPU, expose it through an API, and measure whether it returned useful structured output.
Today, the project is something very different.
Pegas now behaves like a small internal Request Desk for a fictional company. A user sends one request. The system interprets it, decides whether it is safe to continue, routes it to the right specialist, asks another agent to review the proposed result, and can return the task for one correction if necessary.
More importantly, the frontend shows what is actually happening.
The graph is not a staged animation. The handoffs are not decorative. The context shown in the UI is the context the next agent really received.
That shift, from “a model that answers” to “a system that coordinates work,” was the main milestone of this session.
The architecture stayed simple on purpose
We did not add a second model, a separate GPU for every role, or a heavy orchestration framework.
All AI roles still run on the same self-hosted Qwen3 4B model through the existing stack:
Browser
-> Next.js / Vercel
-> Request Desk workflow API
-> Modal
-> Ollama
-> Qwen3 4B on NVIDIA L4textThe important change is above the model layer.
Different agents now have different instructions, different contracts, different allowed outputs, and different responsibilities. The orchestration itself is deterministic TypeScript backend logic. It decides which role can run next, validates outputs, applies safety rules, creates handoffs, and stops loops.
That distinction matters.
The “orchestrator” is not another AI pretending to be a manager. It is code.
The agents do the semantic work. The backend controls the workflow.
The agents
Intake Agent: understand before routing
Every normal request starts with Intake.
Its job is not to solve the request. It extracts the structure needed for the rest of the workflow:
- what the request is about;
- which department is the likely candidate;
- priority;
- confidentiality;
- whether privacy review may be needed;
- what information is missing;
- why the proposed route makes sense.
This turned out to be one of the most important design decisions.
If the first agent tries to both understand the request and complete the final task, there is very little left for the rest of the system to coordinate. Instead, Intake produces a constrained intermediate state.
That state changes what happens next.
If the request is clear and ordinary, the workflow continues to a department agent.
If it is too vague, the workflow can stop with Needs information and ask one concrete clarification question.
If it contains obvious credential-like material, deterministic preflight rules stop the request before the model is called at all.
And if it contains non-secret but sensitive information, it can be sent through Privacy first.
Privacy Agent: reduce context, not just label it
Privacy is conditional. It does not run on every request.
That was intentional.
A normal billing request should not visit a privacy agent just because the graph has a Privacy node. Running every node “for completeness” would turn the workflow into theatre.
Privacy is activated only when Intake or deterministic policy detects that the request needs additional protection.
Its role is also more than classification.
Privacy can return:
- continue;
- manual review;
- needs information.
But the most important part is that Privacy can change the context that continues through the system.
For a normal request, the selected department can receive the usual sanitized request context.
For a privacy-sensitive request, the next agent can receive a reduced brief instead: the task, routing information, confidentiality level, allowed evidence, and recipient restrictions, without automatically receiving the complete sanitized source text.
In other words, Privacy is not just saying “this is confidential.”
It can actually enforce a smaller information surface.
And once context has been removed, later correction or rerouting is not allowed to silently restore the larger pre-Privacy payload.
Department Agents: different specialists, not one generic prompt
The current Request Desk has three specialist department agents:
- Technical
- Business
- Finance
Only one is selected on the first pass.
Each is a separate model call with its own role instructions. That is important because “multi-agent” can otherwise become a cosmetic label for one generic prompt reused several times.
The Technical agent is expected to handle integration and API problems.
The Business agent handles partnership and commercial coordination scenarios.
The Finance agent handles invoices, duplicate charges, billing questions, and similar requests.
The selected agent receives a projected context from Intake or Privacy and returns a department proposal: a summary, priority, department note, recommended next action, questions, and supporting evidence.
The other department agents are explicitly skipped.
The UI reflects that actual route rather than lighting up every possible agent.
Reviewer Agent: the system is allowed to disagree with itself
The Reviewer is the step that made the workflow feel much more like a system and much less like a chain of prompts.
It receives the sanitized request plus the validated Intake result and the selected department proposal. It checks whether the proposed routing and response still match the source request and workflow rules.
The Reviewer can approve the result, request more information, require manual review, or ask for a revision.
Phase 2 added a bounded correction loop.
If Reviewer #1 requests a correction in the same department, that department can run once more and the revised proposal goes to Reviewer #2.
If Reviewer #1 decides the request belongs to another allowed department, the workflow can reroute once to that department and then run Reviewer #2.
Reviewer #2 is terminal.
There is no third correction, no endless agent conversation, and no “keep trying until something looks good.”
That bounded loop was a deliberate safety and cost decision.
Routing is a real backend decision
The current high-level paths now look like this:
Preflight
-> Intake
-> Department
-> Reviewer
-> Final resulttextFor a privacy-sensitive request:
Preflight
-> Intake
-> Privacy
-> Department
-> Reviewer
-> Final resulttextFor an underspecified request:
Preflight
-> Intake
-> Needs information
-> ENDtextFor obvious credentials or restricted input:
Preflight
-> Manual review
-> ENDtextAnd when review requests one correction:
Department
-> Reviewer #1
-> Department revision / reroute
-> Reviewer #2
-> ENDtextThe model proposes semantic decisions, but deterministic code still controls the legal transitions.
That means a model cannot create an infinite loop, invent a new department, or downgrade a hard restricted-policy floor and continue automatically.
Handoffs became first-class objects
One of the strongest changes today was turning agent-to-agent context into something inspectable.
Every real transition can create a handoff containing:
- source agent;
- target agent;
- reason;
- forwarded context;
- fields that were withheld.
The key rule is simple:
the context shown in the Handoff Inspector is the context that was actually serialized into the next model call.
We did not want a polished summary in the UI while secretly sending a larger object behind the scenes.
That would make the orchestration impossible to audit.
On the frontend, a user can now inspect transitions such as:
Intake -> Business
Business -> Reviewertextor:
Intake -> Privacytextand see both what was passed and what was withheld.
This is especially useful for the Privacy path because the effect of the privacy decision becomes visible. The user can see that the next agent did not simply receive the entire previous state.
The frontend now reflects the workflow instead of explaining it
The homepage changed significantly with the architecture.
The central message is now:
One request. The right team.
The main graph shows the current role states:
- running;
- completed;
- skipped;
- not needed;
- failed.
Those states are driven by real backend events over the workflow stream. There are no timers pretending that an agent has completed before the backend says so.
A normal Finance request visibly becomes:
Intake -> Finance -> Reviewertextwhile Technical and Business remain skipped.
A sensitive request can visibly activate Privacy.
A result card then shows the actual final department, priority, review outcome, summary, department note, next action, and route explanation.
The detailed event trace still exists, but it is no longer the main product. It is collapsed behind View activity.
That was another important product lesson: observability is useful, but raw event logs should not dominate the interface. The graph and handoffs should explain the workflow first; the timeline is there when someone wants to inspect deeper.
Why we stopped treating Benchmark as the product
The old Pegas interface gave Benchmark a prominent place because the original project was a single-step triage experiment.
That benchmark still matters as historical evidence, but it measures a different system.
The current Request Desk is not just a classifier. It contains conditional execution, multiple roles, context projection, review, privacy rules, corrections, and handoffs.
So Benchmark was removed from the primary navigation.
The public navigation now focuses on:
Demo
Guide
BlogtextThe legacy benchmark remains available as a historical single-step experiment and regression reference. We did not delete inconvenient old numbers or relabel them as evidence for the new architecture.
That separation makes the project story much clearer.
Small models force you to engineer the contract
One of the most useful lessons from this session came from failures.
The first multi-agent implementation looked correct architecturally, but Qwen3 4B would occasionally produce structured output that was semantically fine and mechanically invalid.
We saw failures such as:
- optional fields using
nullinstead of an empty string; - harmless extra keys;
- evidence being phrased slightly differently;
- Reviewer output failing a strict schema on one run but not the next;
- explanatory fields exceeding a fixed character limit.
For example, Intake could produce a perfectly understandable routing explanation that happened to exceed the allowed route_reason length. Initially, that caused the entire workflow to fail.
The fix was not to make every field loose.
We split the contract into two categories.
Control fields stay strict:
- department;
- decision;
- priority;
- confidentiality;
- privacy state;
- correction target.
If these are invalid, the workflow should not guess.
Descriptive fields are hardened:
- safe
null/ empty normalization; - missing optional arrays receive safe defaults;
- irrelevant extra wrapper objects can be handled;
- invalid evidence can be dropped instead of crashing the run;
- long narrative fields can be safely bounded;
- one structured-output repair attempt is allowed.
This made the system much more reliable without weakening the decisions that control routing.
The lesson is simple: asking a model for JSON is not the same as having a reliable structured interface.
The backend still has to own the contract.
One model, multiple agents
Another important point is what “multi-agent” means here.
Pegas does not run a separate foundation model for Intake, Privacy, Finance, Business, Technical, and Review.
They all use the same Qwen3 4B deployment.
The specialization comes from:
- separate role prompts;
- separate structured schemas;
- different projected inputs;
- different allowed outputs;
- deterministic routing between them.
This keeps the infrastructure small enough for a portfolio project while still making the orchestration real.
It also makes the experiment more interesting: how far can one relatively small self-hosted model go when the application around it is carefully structured?
Safety is partly AI and partly code
The workflow deliberately does not delegate every safety decision to the model.
Credential-like input is stopped by deterministic preflight logic before any model call.
A hard restricted classification cannot be downgraded by Privacy and automatically forwarded.
A second requested correction does not start a third loop.
If the system cannot route safely, it stops at Manual review required or Needs information.
This hybrid approach was more useful than trying to make one prompt contain every safety rule.
The model handles ambiguity and semantics.
Code enforces non-negotiable workflow boundaries.
What changed in Pegas today
The largest change is not visual, even though the product looks very different.
Previously, Pegas mainly demonstrated:
We can self-host an open-weight model and call it from a web application.
Now it demonstrates:
We can turn that model into a coordinated set of specialized roles, route work based on model output, constrain those transitions with deterministic rules, pass only selected context between roles, review and correct the result, and make the whole process visible.
That is a much stronger system story.
The self-hosted model is still the foundation.
But the interesting part is no longer the single inference request.
It is what happens between requests.
What comes next
There is still room to evolve the architecture.
The current department agents are an incremental implementation, and the Request Desk can later move closer to the final V3 topology where routing itself becomes a more explicit stable role rather than representing departments as separate agents.
The workflow can also be evaluated as a workflow, not just as the old classifier: route correctness, context preservation, privacy enforcement, correction behavior, call budget, duration, and failure modes.
But today’s milestone is already substantial.
Pegas now has:
- a self-hosted open-weight model;
- specialized AI roles;
- real conditional routing;
- an optional privacy path;
- bounded reviewer feedback;
- deterministic safety rules;
- inspectable context handoffs;
- backend-driven visualization.
The project did not become more interesting because we added more prompts.
It became more interesting because the outputs of those prompts now change what the system does next.