How It Works
draftandreviewsteps execute sequentially.- The
conditionfunction receives the step context. - If it returns
True, thetrue_stepsbranch executes. - If it returns
False, thefalse_stepsbranch executes.
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
If/else branching based on step output.
from definable.agent import Agent
from definable.agent.workflow import Workflow, Step, Condition
reviewer = Agent(model="gpt-4o", instructions="Review content. End with APPROVED or REJECTED.")
publisher = Agent(model="gpt-4o", instructions="Format and publish the approved content.")
rewriter = Agent(model="gpt-4o", instructions="Rewrite and improve the rejected content.")
workflow = Workflow(
name="review-pipeline",
steps=[
Step(name="draft", agent=drafter),
Step(name="review", agent=reviewer),
Condition(
name="quality-gate",
condition=lambda ctx: "APPROVED" in (ctx.get_last_step_content() or ""),
true_steps=Step(name="publish", agent=publisher),
false_steps=Step(name="rewrite", agent=rewriter),
),
],
)
draft and review steps execute sequentially.condition function receives the step context.True, the true_steps branch executes.False, the false_steps branch executes.Condition(
name="gate",
condition=lambda ctx: score > 7,
true_steps=[
Step(name="polish", agent=editor),
Step(name="publish", agent=publisher),
],
false_steps=Step(name="rewrite", agent=writer),
)
async def check_quality(ctx):
content = ctx.get_last_step_content()
# Call an external API, run evaluation, etc.
return "APPROVED" in content
Condition(name="gate", condition=check_quality, ...)