portia.builder.step_v2
Interface for steps that are run as part of a PlanV2.
StepV2 Objects
class StepV2(BaseModel, ABC)
Interface for steps that are run as part of a plan.
run
@abstractmethod
async def run(run_data: RunContext) -> Any
Execute the step.
to_legacy_step
@abstractmethod
def to_legacy_step(plan: PlanV2) -> Step
Convert this step to a Step from plan.py.
A Step is the legacy representation of a step in the plan, and is still used in the Portia backend. If this step doesn't need to be represented in the plan sent to the Portia backend, return None.
LLMStep Objects
class LLMStep(StepV2)
A step that runs a given task through an LLM (without any tools).
__str__
def __str__() -> str
Return a description of this step for logging purposes.
run
@override
@traceable(name="LLM Step - Run")
async def run(run_data: RunContext) -> str | BaseModel
Run the LLM query.
to_legacy_step
@override
def to_legacy_step(plan: PlanV2) -> Step
Convert this LLMStep to a Step.
InvokeToolStep Objects
class InvokeToolStep(StepV2)
A step that calls a tool with the given args (no LLM involved, just a direct tool call).
__str__
def __str__() -> str
Return a description of this step for logging purposes.
run
@override
@traceable(name="Invoke Tool Step - Run")
async def run(run_data: RunContext) -> Any
Run the tool.
to_legacy_step
@override
def to_legacy_step(plan: PlanV2) -> Step
Convert this InvokeToolStep to a legacy Step.
FunctionStep Objects
class FunctionStep(StepV2)
Calls a function with the given args (no LLM involved, just a direct function call).
__str__
def __str__() -> str
Return a description of this step for logging purposes.
run
@override
@traceable(name="Function Step - Run")
async def run(run_data: RunContext) -> Any
Run the function.
to_legacy_step
@override
def to_legacy_step(plan: PlanV2) -> Step
Convert this FunctionStep to a legacy Step.
SingleToolAgentStep Objects
class SingleToolAgentStep(StepV2)
A step where an LLM agent uses a single tool (calling it only once) to complete a task.
__str__
def __str__() -> str
Return a description of this step for logging purposes.
run
@override
@traceable(name="Single Tool Agent Step - Run")
async def run(run_data: RunContext) -> None
Run the agent step.
to_legacy_step
@override
def to_legacy_step(plan: PlanV2) -> Step
Convert this SingleToolAgentStep to a Step.
ConditionalStep Objects
class ConditionalStep(StepV2)
A step that represents a conditional clause in a conditional block.
I.E. if, else-if, else, end-if clauses.
validate_conditional_block
@field_validator("conditional_block", mode="after")
@classmethod
def validate_conditional_block(cls,
v: ConditionalBlock | None) -> ConditionalBlock
Validate the conditional block.
block
@property
def block() -> ConditionalBlock
Get the conditional block for this step.
__str__
def __str__() -> str
Return a description of this step for logging purposes.
run
@override
@traceable(name="Conditional Step - Run")
async def run(run_data: RunContext) -> Any
Run the conditional step.
to_legacy_step
@override
def to_legacy_step(plan: PlanV2) -> Step
Convert this ConditionalStep to a PlanStep.