Skip to main content

run_agent

Runs an AI agent loop from Python code.

Use this function inside regular workflow stages (Tasklet, Job, Hook, or Form logic) when you need multi-step reasoning and tool use.

Syntax

from abstra.ai import run_agent

result = run_agent(
prompt,
tools=None,
max_steps=30,
)

Parameters

NameDescriptionTypeDefault
prompt (required)Prompt input for the agent. Can be a string or a list of prompt items (text/files/images).Prompt | list[Prompt]None
toolsList of tools the agent can call. Each item can be a callable function or an AgentTools instance.list[Callable | AgentTools] | NoneNone
max_stepsMaximum number of reasoning/tool-use iterations.int30

Example: Use Task Data

from abstra.ai import run_agent
from abstra.tasks import get_trigger_task

task = get_trigger_task()

result = run_agent(
prompt=f"""
You are handling a support request.
Customer: {task.payload.get("customer_name")}
Message: {task.payload.get("message")}

Return a concise suggested response.
""",
max_steps=20,
)

print(result)

Example: Custom Tool

from abstra.ai import run_agent

def lookup_order(order_id: str) -> str:
"""Returns the status of a given order."""
return "Order is in transit."

result = run_agent(
prompt="Check order 123 and explain status to the user.",
tools=[lookup_order],
)

Notes

  • Tool names are derived from Python function/method names.
  • Add type hints and docstrings to improve tool calling accuracy.