Browse documentation
Home
View Markdown
On this page

Run your first agent

Run a Python agent locally with a scripted model and a tool that looks up an order. The example uses Python 3.12 or newer and needs no API key or network.

Install gvn

pip install gvn

The core package has no dependencies of its own. Install covers the optional extras and the companion packages.

Run the example

Save this as first_agent.py.

import asyncio

from gvn.harness.messages import Message, ToolCall
from gvn.harness.ports import Reply
from gvn.kernel.schema import Record, Text
from gvn.shortcuts import FunctionTool, run_agent
from gvn.testing.fakes import ScriptedModel


def order_status(order_id: str) -> dict[str, str]:
    return {"order_id": order_id, "status": "shipped"}


tool = FunctionTool(
    name="order_status",
    description="Look up an order's shipping status.",
    arguments=Record({"order_id": Text()}),
    function=order_status,
)
model = ScriptedModel(script=[
    Reply(message=Message.assistant(calls=[
        ToolCall(call_id="lookup-1", name="order_status", arguments={"order_id": "A-17"}),
    ])),
    Reply(message=Message.assistant(text="Order A-17 has shipped.")),
])

run = asyncio.run(run_agent(
    instructions="Look up the order before answering.",
    prompt="Where is order A-17?",
    model=model,
    tools=[tool],
))
assert run.outcome().payload()["tools"][0]["content"]["status"] == "shipped"
print(run.outcome().payload()["text"])

Run it with python first_agent.py. Expected output follows.

Order A-17 has shipped.

The scripted model requests order_status, gvn checks the arguments and calls your function, and the model returns its scripted reply. The script controls the reply, so its output is repeatable. The shortcuts guide explains what run_agent sets up and how to set a policy for tool calls.

Keep building

Choose your path gives an ordered route for what you came to do: build your own harness, try gvn in an afternoon, evaluate it, or brief a coding agent. The usual next steps: