Skip to main content

Examples

Agent with tables

This agent receives a support ticket and categorizes it into a database table.

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

task = get_trigger_task()

run_agent(
prompt=f"""
You received a support ticket:

- From: {task.payload.get("customer_email")}
- Subject: {task.payload.get("subject")}
- Message: {task.payload.get("message")}

Categorize this ticket by inserting a row into the `support_tickets` table with:
- email: the customer's email
- category: one of "billing", "technical", "general"
- priority: one of "low", "medium", "high"
- summary: a one-sentence summary of the issue
""",
tools=[TablesTools(method=["insert"], table="support_tickets")],
)

Agent with connectors

This agent sends a Slack message when a new order is placed.

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

task = get_trigger_task()
items = task.payload.get("items", [])

run_agent(
prompt=f"""
A new order was placed:

- Customer: {task.payload.get("customer_name")}
- Total: ${task.payload.get("total")}
- Items: {len(items)} items

Send a message to the #orders Slack channel with a summary of this order.
""",
tools=[ConnectorsTools(connection="slack", action="send_message")],
)

Agent with custom tools and transitions

This agent reviews a document and routes it to the appropriate next stage using task transitions.

from abstra.ai import run_agent, FilesTools
from abstra.tasks import get_trigger_task, send_task

task = get_trigger_task()

def approve(summary: str) -> str:
"""Mark the document as approved and forward it with a summary."""
send_task("approved", {"summary": summary})
return "Document approved and forwarded."

def reject(missing_fields: str) -> str:
"""Mark the document as rejected with the list of missing fields."""
send_task("rejected", {"missing_fields": missing_fields})
return "Document rejected and forwarded."

run_agent(
prompt=f"""
Review the following document submission:

- Type: {task.payload.get("document_type")}
- Submitted by: {task.payload.get("submitted_by")}

The document is stored at: {task.payload.get("file_path")}

Read the document and determine if it is complete. Then:
- If complete, call approve() with the document summary
- If incomplete, call reject() with the missing fields
""",
tools=[
FilesTools(actions=["read_text"], globs=[task.payload.get("file_path", "*")]),
approve,
reject,
],
)

Agent with images

This agent analyzes an image attached to the task. Images are automatically sent to the LLM as visual content.

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

task = get_trigger_task()

run_agent(
prompt=[
"""Extract the following information from the receipt:
- Store name
- Date
- Total amount
- List of items with prices

Insert the data into the `receipts` table.""",
task.payload.get("receipt_image"),
],
tools=[TablesTools(method=["insert"], table="receipts")],
)

Agent with browser

This agent navigates to a website and extracts information.

from abstra.ai import run_agent, BrowserTools

run_agent(
prompt="""
Go to https://news.ycombinator.com and extract the top 5 stories.
For each story, get the title, URL, and point count.
Return the results as a structured summary.
""",
tools=[BrowserTools(url="https://news.ycombinator.com")],
max_steps=10,
)

Simple agent with custom tools

This agent uses plain Python functions as tools — no toolkit classes needed.

from abstra.ai import run_agent

def lookup_order(order_id: str) -> str:
"""Returns the status of a given order by its ID."""
orders = {
"123": "In transit - arriving March 15",
"456": "Delivered on March 10",
}
return orders.get(order_id, "Order not found")

def calculate_shipping(weight_kg: float, destination: str) -> str:
"""Calculates shipping cost based on weight and destination."""
base_cost = weight_kg * 5.0
if destination == "international":
base_cost *= 2.5
return f"R${base_cost:.2f}"

result = run_agent(
prompt="Check orders 123 and 456. Then calculate shipping for a 3kg international package.",
tools=[lookup_order, calculate_shipping],
)

print(result)