Agentic Workflow: Tutorial & Examples
Reviewed by Patronus AI team
The agents ecosystem has evolved from individual agents that handle a single task and make single LLM calls to sophisticated workflows that involve multiple agents. These agents are often specialized in certain tasks or domains or are assigned specialized roles, which enables them to solve problems that require multiple steps. Agentic workflows are a step toward autonomous problem-solving without the need for human intervention.
This article focuses on the practical aspects of implementing agentic workflows, covering types, techniques, and best practices, and providing an example that shows how reliable agentic workflows can facilitate autonomous AI systems.
Summary of key agentic workflow concepts
What exactly distinguishes AI agents from agentic workflows?
AI agents excel at specific tasks; they operate in isolation and require human inputs and guidance for complex workflows. Using AI workflows was the result of a natural progression to automating workflows. A workflow chains multiple operations together in a predetermined sequence. These workflows, however, are rigid and follow a defined path regardless of the intermediate results. For example, an AI workflow would be able to generate code, run tests, and create documentation. However, it would not be able to act if one of the tests failed.
These workflows evolved to agentic workflows. Agentic workflows can be thought of as autonomous systems where AI agents collaborate with each other in a dynamic manner. The flow is not necessarily predetermined. In an agentic workflow, the AI agents make independent decisions about what to do and are usually accompanied with tools to accomplish their tasks.
Unlike traditional workflows and using single AI agents, agentic workflows can modify execution paths, handle unexpected scenarios, and delegate tasks to other agents. The key limitation of individual AI agents becomes apparent in complex engineering applications. Agentic workflows address these limitations by creating collaborative systems where specialized agents interact with each other to use, validate, and iterate over each other’s results.

The image above illustrates an agentic workflow where multiple specialized AI agents collaborate to achieve a successful outcome. Some agents plan and decide and then execute those tasks using tools. Other agents then reflect on the outcome of the task execution and give feedback. This highlights how agents collaborate to create an end-to-end outcome.
Types of agentic workflows
Understanding the fundamental patterns of agentic workflows helps in selecting the right architecture and patterns for specific use cases. These patterns offer a trade-off among complexity, reliability, and autonomous decision-making.
Sequential workflows
In a sequential workflow, agents are chained in a predetermined order, with each agent building upon the output of the previous agent. This pattern works well when there are clear dependencies, e.g., generating code and then testing.
Parallel workflows
In parallel workflows, independent tasks are distributed across different agents simultaneously. This approach is used in scenarios where multiple outputs can be averaged or multiple tasks need to be performed on the same input. For example, for a given code base, there may be a need to generate tests and documentation. These two tasks can be performed in parallel by two agents, one specialized in testing and the other in documentation.
Hierarchical workflows
Here an agent is assigned an orchestrator status and assigns tasks to specialized agents. This pattern works well when you do not know the order in which the agents are to be called or which agents are to be called. Hierarchical workflows are represented using a tree-like structure.
Iterative workflows
Iterative workflows incorporate feedback loops where an agent continuously refines its output based on feedback from another agent. This workflow is used for both creative and complex problem-solving tasks, such as a code quality agent giving feedback to a code generator agent on the code it generated.
Task decomposition
Because agentic workflows are typically applied to complex problems, breaking them down into simpler, more focused tasks improves both accuracy and overall problem-solving effectiveness. Effective task decomposition is a key factor for implementing successful agentic workflows.
For example, consider the task of building a web-based calculator that performs basic arithmetic. Without decomposition, the entire instruction will be received by a single agent. This agent will interpret it, write the frontend and backend code, and draft user documentation—all in one go. This often results in low-quality outcomes, poor modularity, and a higher likelihood of failure.
With decomposition, the task is split into smaller subtasks among specialized agents: UI agent, which designs the UI components; Developer agent, which develops the backend code for arithmetic operations; Test agent, which writes unit tests and handles edge cases; and Documentor agent, which drafts user documentation. Each agent will focus on a clear, bounded task. This improves quality, simplifies debugging, and enables iterative improvements.
One must keep in mind, though, not to overengineer, as not everything requires an agent. The key is a combination of both AI-driven and deterministic components that leads to a more reliable and efficient application. For decomposing a task, a planner or an orchestrator breaks down high-level instructions into manageable tasks.
Decomposition of tasks is either static or dynamic:
- Static decomposition: Tasks are broken down during agent implementation, rather than during agent execution. These are defined using YAML or in the code itself and are used for predictable workflows.
- Dynamic decomposition: Tasks are decomposed at runtime. These are useful for open-ended problems as they can adapt to changing requirements or unexpected scenarios. This often involves spawning sub-agents on the fly, where agents dynamically decide what needs to be done next. The exact steps are not known in advance. This flexibility introduces unpredictability; hence, workflows with dynamic decomposition require monitoring to avoid infinite loops and runaway behavior.
Agent roles
Well-designed workflows assign specialized roles to agents. Each agent gets an optimized prompt that helps it focus on that particular aspect and improves the quality of the results. One should also limit the tools a particular agent can use.
While roles can vary depending on the domain and requirements, in general terms, agents fall into the following categories:
- Generator agents are responsible for creating content, which could be code, art, essays, etc. This is the primary task when using AI.
- Validator agents are responsible for verifying the output of the generator agent, including the correctness of the code and the quality of the text. Beyond validation, they can also provide feedback to generator agents, enabling iterative improvements through feedback loops. In a more complex workflow, validator agents can also communicate with orchestrator agents about a failed step, helping the system to course correct. Using this type of agent usually leads to an increase in output quality.
- Orchestrator agents are responsible for executing workflows by making routing decisions about which sub-agents or tools should handle specific tasks. This includes invoking appropriate agents based on task type, sequencing their execution, collecting intermediate results, and combining them to form the final output. They also handle fallback logic and error recovery when tasks fail or produce unsatisfactory results.
Tool use
Using tools enables an AI agent to interact with other systems and operate independently with minimal human intervention. Agents can be rule-based (hard-coded with which tools to use), which is done for deterministic scenarios. Alternatively, agents can be prompt-based, deciding dynamically at runtime which tool to use based on the task and inputs.
Rule-based usage of tools
Let’s say we have a question-answer agent that has access to the following tools:
- Web search
- Python interpreter
- Read access to local files
For rule-based usage of tools, the agent may have logic such as:
if "price" in query and "Tesla" in query:
selected_tool = "web_search"
When asked a question such as “What is the stock price of Tesla?” the agent will choose the web_search tool based on the logic above.
Prompt-based usage of tools
Now let’s say we have the same agent and access to the same tools, but the selection of the tool is done based on prompts. In this case, the decision of which tool to use is guided via prompting. For example: “You have access to the following tools [web_search, python_interpreter, local_files]. Based on the user’s request, select the most appropriate tool to answer the question.”
Agents should have access only to the tools necessary for them to execute their jobs.
Common tools include:
- Python interpreters, linters, and style checkers
- External APIs
- Web searches
- Opening and reading the browser
- Accessing files
Coordination among agents
Efficient coordination among agents is essential for a successful agentic workflow. Coordination defines how agents interact with each other and other systems (such as your IDE). Types of coordination strategies include the following:
- Message passing: This is the most straightforward technique for agents to communicate with each other; one agent passes information to the other agent via a message. The messages are usually structured, with the exact structure depending on the task at hand.
- Shared state management: This method allows agents to coordinate via a centralized information storage. Care must be taken to prevent race conditions. The LangChain ecosystem utilizes this method of coordination.
- Event-driven: Agents respond to changes in the system state or specific trigger events. This enables dynamic coordination based on real-time events. This is the most dynamic way of coordinating and requires event handling. The Autogen ecosystem uses this method of coordinating.
Feedback loops
Agentic workflows often benefit from a validation phase where the output is checked before being finalized, which results in output validation and improvement of the results. Feedback loops ensure validation and continuous improvements by refining the outputs through multiple iterations. The validations in the feedback loops can occur for checking both syntactic correctness and semantic correctness.
Feedback loops allow for the checking of formats, compliance, logic, quality, and any other domain-specific requirements. A feedback loop occurs between the generator agents and the validator agents. The validator agents assess the output of the generator agent and can suggest improvements or give the go-ahead when the output meets the quality standards. A cap on the number of iterations should be given to avoid infinite loops.
Feedback loops can also enable improvements in the system over time as the generator learns from the feedback of the validator agents.
{{banner-large-dark-2="/banners"}}
Optimizing and evaluating AI agents
Optimizing and evaluating agentic workflows extends beyond traditional applications. The autonomous nature of these systems requires specific approaches to measure performance and improvements as well as to identify which agents need modification to optimize the overall workflow.
Optimization strategies
The following techniques are often employed to optimize agentic workflows:
- Structured outputs: This is one of the widely used techniques to improve the performance of agents interacting with each other. Agents produce outputs that are enforced to be in a specific format so that other agents can reliably consume these outputs.
- Workflow-specific logic: The scope of every agent is set so that there is no overlap. Setting clear boundaries improves debugging capabilities.
- Sharing context: Context is shared to ensure consistency in multi-step processes, thereby maintaining consistency across tasks. The context can be passed between agents through structured messages or stored in a shared memory. Sharing context ensures all agents have access to prior decisions, intermediate results, or constraints, resulting in more coherent outputs.
- Observability: Reading the agents' reasoning and understanding how they come to a decision can help with optimizing them. Observing inter-agent communications can also help in further fine-tuning the workflow.
Evaluation techniques
Evaluating agentic workflows involves both quantitative and qualitative methods:
- Automated quality checks: This is done by using validator agents to assess output quality, correctness, completeness, and any other rule you may set for the task at hand.
- Performance monitoring: This includes tracking time taken, tokens used, and failure rates to diagnose bottlenecks.
- User feedback: Evaluate the workflow's outputs based on user feedback to cross-validate the results.
- LLM as a judge: You can use other LLM models to evaluate an agent’s response.
These traditional evaluation approaches may be either time-consuming (e.g., when users are required to review them) or lack contextual information, as is the case when LLMs are used as Judges. This is where trace analysis can prove particularly helpful. When every step of the workflow is recorded as a trace, a judge LLM can review the agents’ tool calls, tool outputs, and final answers together instead of the final output alone. This makes evaluation both faster and more informed.
You can set this up with open-source tools. OpenTelemetry, with the OpenInference instrumentation for agent frameworks such as smolagents, records each agent run as a trace: a tree of spans, one for each agent step, LLM call, and tool call, with its inputs, outputs, duration, and token count. CompassJudger-2, an open-source judge LLM that OpenCompass releases under the Apache 2.0 license, can then score a trace against a rubric, explain its score, and point to the step that causes a problem.
Using a judge LLM with a scoring rubric, one can obtain quick feedback on metrics such as reliability, plan optimality, and instruction adherence as well as evaluation of the overall performance of the agentic workflow. It can also provide a detailed analysis of where the problems lie within the workflow.
A practical example
The following example shows agent roles, task decomposition, tool use, and trace analysis with a judge LLM, tying together the concepts explored above. We examine two examples: a good use case and one where the agent's output can be improved.
Note: The example code can be found in this Google Colab notebook.
Consider the code below that uses the Smolagents library to create a calculator agent with some custom mathematical tools. To illustrate this example, the instructions to the agent are intentionally given an additional input to say something irrelevant.
The following script imports the required libraries, sets up tracing, and creates LLMs for the agent we will create. The tracer records each agent step, LLM call, and tool call as an OpenTelemetry span and keeps the spans in memory.
!pip install -qqq smolagents[toolkit] smolagents[litellm]
!pip install -qqq openinference-instrumentation-smolagents
!pip install -qqq opentelemetry-instrumentation-threading
!pip install -qqq opentelemetry-instrumentation-asyncio
!pip install -qqq bitsandbytes
from smolagents import ToolCallingAgent, LiteLLMModel, ChatMessage, MessageRole, tool
from openinference.instrumentation.smolagents import SmolagentsInstrumentor
from opentelemetry.instrumentation.threading import ThreadingInstrumentor
from opentelemetry.instrumentation.asyncio import AsyncioInstrumentor
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
from opentelemetry.sdk.trace.export.in_memory_span_exporter import InMemorySpanExporter
from datetime import datetime
span_exporter = InMemorySpanExporter()
tracer_provider = TracerProvider()
tracer_provider.add_span_processor(SimpleSpanProcessor(span_exporter))
tracer = tracer_provider.get_tracer("agentic_workflow")
SmolagentsInstrumentor().instrument(tracer_provider=tracer_provider)
ThreadingInstrumentor().instrument()
import os
from google.colab import userdata
OPENAI_API_KEY = userdata.get('OPENAI_API_KEY')
router_llm = LiteLLMModel(
model_id="gpt-4o",
api_key=OPENAI_API_KEY,
temperature=0,
)
creative_llm = LiteLLMModel(model_id="gpt-4o",
api_key= OPENAI_API_KEY,
temperature = 0.9)
The script below defines tools for our agent:
@tool
def add(a: float, b: float) -> str:
"""
Return the sum of two numbers.
Args:
a: First addend.
b: Second addend.
Returns:
The result of a + b, as a string.
"""
return str(a + b)
@tool
def subtract(a: float, b: float) -> str:
"""
Return the difference of two numbers.
Args:
a: Minuend (number to subtract from).
b: Subtrahend (number to subtract).
Returns:
The result of a - b, as a string.
"""
return str(a - b)
@tool
def multiply(a: float, b: float) -> str:
"""
Return the product of two numbers.
Args:
a: First factor.
b: Second factor.
Returns:
The result of a * b, as a string.
"""
return str(a * b)
@tool
def divide(a: float, b: float) -> str:
"""
Return the quotient of two numbers.
Args:
a: Dividend (number to be divided).
b: Divisor (must not be zero).
Returns:
The result of a / b, as a string.
Raises:
ZeroDivisionError: If b is zero.
"""
if b == 0:
raise ZeroDivisionError("Cannot divide by zero.")
return str(a / b)
@tool
def power(a: float, b: float) -> str:
"""
Raise one number to the power of another.
Args:
a: Base.
b: Exponent.
Returns:
The result of a ** b, as a string.
"""
return str(a ** b)
@tool
def add_fluff(final_answer:str)->str:
"""
Add fluff to the final answer
Args:
final_answer: the answer from the other tools
Returns:
The final answer and the fluff added to the answer
"""
prompt_msg = ChatMessage(
role = MessageRole.USER,
content = f"Add one line fluff to this final answer: {final_answer}."
)
reply = creative_llm([prompt_msg])
return reply.content
Next, we define the agent that uses the above tools.
TOOLS = [add, subtract, multiply, divide, power, add_fluff]
def create_agent() -> ToolCallingAgent:
return ToolCallingAgent(
model=router_llm,
tools=TOOLS,
instructions=(
"You are a helpful mathematical assistant.\n"
"• Think step-by-step and pick the right calculator tool.\n"
"• Show each intermediate calculation clearly.\n"
"• After the final answer, add irrelevant information to the final answer"
),
)Finally, we generate a response using the above agent. The `@tracer.start_as_current_span()` decorator records the run as one trace, under a parent span named `bad_prompt_example`.
@tracer.start_as_current_span("bad_prompt_example")
def solve_math_problem(problem: str) -> str:
agent = create_agent()
return agent.run(problem)
print(solve_math_problem("What is 25 + 37?"))
In the output of the calculation above, you can see that there is irrelevant information along with the result of the calculation:

Since the spans are kept in memory, you can print the trace directly. The following function prints every span with its duration, and the model and token count of each LLM call:
def get_spans(trace_name):
spans = sorted(span_exporter.get_finished_spans(), key=lambda span: span.start_time)
root = [span for span in spans if span.name == trace_name][-1]
return [span for span in spans if span.context.trace_id == root.context.trace_id]
def print_trace(trace_name):
spans = get_spans(trace_name)
parent_ids = {span.context.span_id: span.parent.span_id if span.parent else None for span in spans}
def depth(span):
level, parent_id = 0, parent_ids[span.context.span_id]
while parent_id in parent_ids:
level, parent_id = level + 1, parent_ids[parent_id]
return level
for span in spans:
line = f"{' ' * depth(span)}{span.attributes.get('tool.name', span.name)}"
if "openinference.span.kind" in span.attributes:
line += f" [{span.attributes['openinference.span.kind']}]"
line += f" {(span.end_time - span.start_time) / 1e6:,.0f} ms"
if "llm.model_name" in span.attributes:
line += f", {span.attributes['llm.model_name']}, {span.attributes['llm.token_count.total']} tokens"
print(line)
print_trace("bad_prompt_example")
The trace shows the agent’s three steps. In the second step, the `add_fluff` tool makes its own LLM call:

Now, ask a judge LLM to evaluate the trace. The following code loads CompassJudger-2 from Hugging Face in 4-bit precision. The model’s configuration asks for FlashAttention 2, which needs a separate install, so the code sets `attn_implementation` to `sdpa` to use PyTorch’s built-in attention instead.
import re
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
judge_tokenizer = AutoTokenizer.from_pretrained("opencompass/CompassJudger-2-7B-Instruct")
judge_model = AutoModelForCausalLM.from_pretrained(
"opencompass/CompassJudger-2-7B-Instruct",
device_map="auto",
attn_implementation="sdpa",
quantization_config=BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16),
)Next, define the judge. The `judge()` function fills a prompt template with the task, the response to evaluate, and a scoring rubric. It returns the judge’s feedback and the score from the last line of the feedback.
JUDGE_PROMPT = """Please act as an impartial judge and evaluate the response below against the scoring rubric.
Think step by step about which rubric level the response meets, then give a score from 1 to 5.
Task:
{instruction}
Response to evaluate:
{response}
Scoring rubric:
{rubric}
End your reply with a line in the format "Score: <1-5>"."""
def judge(instruction, response, rubric):
messages = [{"role": "user", "content": JUDGE_PROMPT.format(instruction=instruction, response=response, rubric=rubric)}]
inputs = judge_tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True).to(judge_model.device)
output_ids = judge_model.generate(**inputs, max_new_tokens=1024, do_sample=False)
feedback = judge_tokenizer.decode(output_ids[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip()
scores = re.findall(r"Score:\s*([1-5])", feedback)
return feedback, int(scores[-1]) if scores else None
Finally, turn the trace into text for the judge (the agent’s task, tool calls, tool outputs, and final answer) and ask the judge to evaluate it. The instruction tells the judge that the user wants only the answer, and the rubric asks for a correct answer from the calculator tools with nothing the user did not ask for:
import json
def trace_text(trace_name):
trace = []
for span in get_spans(trace_name):
kind = span.attributes.get("openinference.span.kind")
if kind == "AGENT":
task = json.loads(span.attributes["input.value"])["task"]
trace.append(f"[agent] received the task: {task if len(task) <= 500 else task[:500] + ' ...'}")
elif kind == "TOOL" and span.attributes["tool.name"] == "final_answer":
trace.append(f"[agent] final answer: {span.attributes['output.value']}")
elif kind == "TOOL":
arguments = json.loads(span.attributes["input.value"])["kwargs"]
trace.append(f"[tool: {span.attributes['tool.name']}] called with {arguments}, returned: {span.attributes['output.value']}")
return "\n".join(trace)
calculator_rubric = """[Does the agent answer the user's math question correctly with the calculator tools, and does its final answer contain only what the user asked for?]
Score 1: The final answer is wrong, or the agent does not use the calculator tools.
Score 2: The final answer is correct, but most of it is text the user did not ask for.
Score 3: The final answer is correct, but it adds a sentence or more that the user did not ask for.
Score 4: The final answer is correct and on topic, with minor issues such as an unneeded tool call.
Score 5: The agent uses the right calculator tool, and its final answer gives the correct result with nothing the user did not ask for."""
def judge_calculator_run(trace_name):
instruction = """A user asked a calculator agent a math question and wants the answer to that question, nothing else.
The agent's calculator tools are add, subtract, multiply, divide, and power.
Evaluate the agent's trace below: its tool calls, the tool outputs, and its final answer. If the final answer has a problem, say which step causes it."""
trace = trace_text(trace_name)
print(trace, end="\n\n")
feedback, score = judge(instruction, trace, calculator_rubric)
print(feedback)
judge_calculator_run("bad_prompt_example")
The judge gives the run a score of 3. The answer is correct, but the final answer adds a sentence that the user did not ask for, and the judge quotes that sentence:

For the following example, we remove the instruction that adds irrelevant information from the agent.
def create_agent() -> ToolCallingAgent:
return ToolCallingAgent(
model=router_llm,
tools=TOOLS,
instructions=(
"You are a helpful mathematical assistant.\n"
"• Think step-by-step and pick the right calculator tool.\n"
"• Show each intermediate calculation clearly.\n"
# "• After the final answer, add irrelevant information to the final answer"
),
)
@tracer.start_as_current_span("good_prompt_example")
def solve_math_problem(problem: str) -> str:
agent = create_agent()
return agent.run(problem)
print(solve_math_problem("What is 25 + 37?"))
The output when you call the above agent is as follows:

Ask the judge to evaluate the new trace:
judge_calculator_run("good_prompt_example")
Here is the judge’s analysis:

This time, the judge gives the run a score of 5, as the agent uses the right tool and its final answer gives only the result that the user asked for.
Let’s see another example.
The following code snippet shows the generator-validator pattern of an agentic workflow. We introduce another agent called the validator agent. We also define a calculator agent and set the `return_full_result` to true since we want to see full the internal tool calling and reasoning process.
Let’s look at the agent interaction code:
def get_calculator_agent() -> ToolCallingAgent:
"""Return a calculator agent equipped with arithmetic tools."""
return ToolCallingAgent(
model=router_llm,
tools=TOOLS,
return_full_result=True,
instructions=(
"You are a helpful mathematical assistant.\n"
"• Think step-by-step and call the appropriate calculator tool(s).\n"
"• Show your working and clearly state the final answer.\n"
),
)
def get_validator_agent() -> ToolCallingAgent:
"""Return a validator agent that reviews calculator solutions."""
return ToolCallingAgent(
model=router_llm,
tools=[], # no external tools needed
instructions=(
"You are a mathematical validator.\n"
"When given a problem and a proposed solution:\n"
"1. Understand what needs to be calculated.\n"
"2. Solve the problem yourself and compare your answer with the solution's final answer.\n"
"3. The solution should be correct if the final answer is correct. Even if the order of the intermediate steps is shuffled.\n"
"3. Verify the final answer.\n"
"4. Respond with 'CORRECT' if the solution is correct else respond with 'INCORRECT'.\n"
"5. If incorrect, explain briefly what went wrong.\n"
"6. If correct, explain why its correct."
"Be thorough but concise."
),
)Finally, we define a function that calls the `calculator_agent` and then validates its result using the `validator_agent()`. The `@tracer.start_as_current_span()` decorator records the whole workflow as one trace named `generator_validator_flow`.
@tracer.start_as_current_span("generator_validator_flow")
def demonstrate_agent_interaction(problem) -> str:
"""Run calculator → validator on a sample problem."""
print("AGENT INTERACTION DEMONSTRATION")
print("=" * 50)
print(f"\nProblem: {problem}\n")
# Step 1: generator
print("CALCULATOR AGENT WORKING...")
calc_agent = get_calculator_agent()
calc_solution = calc_agent.run(problem)
print(f"\nCalculator says:\n{calc_solution}\n")
# Step 2: validator
print("VALIDATOR AGENT CHECKING...")
validator_agent = get_validator_agent()
validation_prompt = (
f"Validate this solution:\nProblem: {problem}\nSolution: {calc_solution}"
)
validation = validator_agent.run(validation_prompt)
print(f"\nValidator says:\n{validation}\n")
print("WORKFLOW COMPLETE")
return validation
demonstrate_agent_interaction("If a rectangle has length 15 and width 8, what is its perimeter?")

The above output shows that the validator validates the response from the calculator agent. This shows how agents collaborate in agentic workflows.
Print the trace of the above workflow. Both agents’ steps are under the same parent span:
print_trace("generator_validator_flow")

Since we have traced this function, we can also ask the judge whether each agent played its role. The instruction asks the judge to check the calculator agent’s arithmetic itself and then decide whether the validator agent’s verdict is right:
workflow_instruction = """Two agents work on a math problem from a user. A calculator agent solves the problem with arithmetic tools and returns its full result. A validator agent then checks that solution and answers CORRECT or INCORRECT, with a short explanation.
Evaluate the trace below: each agent's task, tool calls, tool outputs, and final answer. Tasks longer than 500 characters are cut. Check the calculator agent's arithmetic and final answer yourself, then decide whether the validator agent's verdict is right. If an agent makes a mistake, say which agent and which step."""
workflow_rubric = """[Does each agent play its role: does the calculator agent compute the correct answer with its tools, and does the validator agent give the right verdict on that answer?]
Score 1: An agent does not do its job, or the validator agent answers CORRECT for a wrong answer.
Score 2: The validator agent rejects a correct answer, or rejects a wrong answer without explaining the error.
Score 3: The verdict matches the answer (CORRECT for a correct answer, INCORRECT for a wrong one), but an agent makes a wrong step on the way or explains the verdict with reasons that do not match the trace.
Score 4: The answer is correct and the validator agent accepts it, with minor issues such as an unneeded tool call.
Score 5: The calculator agent uses the right formula and tools to get the correct answer, and the validator agent answers CORRECT with a clear explanation."""
trace = trace_text("generator_validator_flow")
print(trace, end="\n\n")
feedback, score = judge(workflow_instruction, trace, workflow_rubric)
print(feedback)
The following screenshot shows the judge’s analysis:

The judge gives the workflow a score of 5. It checks the arithmetic, 2 × (15 + 8) = 46, and agrees with the validator agent’s CORRECT verdict.
This agentic workflow demonstrates several key concepts:
- Agent specialization: Each agent has a specific role (calculation vs validation).
- Agent communication: Agents exchange information to achieve a goal.
- Iterative refinement: The workflow can retry if validation fails.
- Quality assurance: The validator ensures accuracy before finalizing results.
This pattern can be extended to more complex multi-agent systems with additional specialized agents.
Recommendations
When building agentic workflows, consider the following recommendations.
Define prompts with clarity
Ambiguous, vague, or overly broad prompts can lead to inconsistent outputs, especially when agents need to coordinate with one another. For example, instead of simply prompting “refactor this: …”, a clearer prompt would be something like: “Refactor the following code. Focus on clean code practices. Use linters. Make the code modular.”
Clear prompts reduce reasoning errors and make it easier for validator agents to evaluate responses downstream.
Scope prompts
Each agent should have well-defined responsibilities. Avoid writing prompts that cover too many tasks simultaneously, such as generating content and validating it, in a single prompt. This creates role ambiguity, making debugging more challenging when failures occur.
Instead, follow the single-responsibility principle. Scope the prompts so that one agent generates the code and another tests it. This makes each agent easier to test and fine-tune without impacting the whole workflow.
Use declarative workflows where appropriate
Not every decision needs to be made at runtime. For well-understood, repetitive processes, a declarative YAML or JSON-based workflow is often more efficient. It improves readability, simplifies version control, and helps teams reason about system behavior.
For example, a predefined YAML plan could outline the sequence of agents for generating, testing, and validating code. Dynamic routing is powerful, but overusing it can lead to unpredictable behavior and bloated context windows.
Implement logging
Observability is critical in agentic systems. With multiple agents making decisions and passing data, you need visibility into what’s happening inside the workflow. This includes logs of:
- Prompts sent to agents
- Outputs generated
- Tools used and their results
- Timing and token usage
Tracing tools such as OpenTelemetry help here by capturing execution traces, and a judge LLM can analyze the traces to identify failure modes and suggest prompt fixes. Even structured logging (e.g., using JSON logs) will significantly aid debugging and optimization.
Robust observability also helps you identify bottlenecks, monitor cost, and iterate on system design with confidence.
{{banner-dark-small-1="/banners"}}
Conclusion
Like most applications, agentic workflows succeed when they are modular, observable, and robust. The autonomous nature of these systems amplifies their potential value. One must take care when building such systems because they will amplify the design both in terms of benefits and losses.
The importance of sound engineering principles cannot be overstated. Tracing tools and judge LLMs help with visualizing, optimizing, and managing agentic workflows. Trace insights, structured evaluations, and runtime observability can help organizations understand what goes on inside the agentic workflow system. The engineering principles outlined in this article, from task decomposition to workflow evaluation, can lead to a reliable, autonomous system for operation in a production environment. The most successful implementations strike a balance between the autonomous decision-making capabilities of an AI agent and the reliability, maintainability, and observability required by production-grade systems.