Skip to content

Building Agents with Vibeflow

An agent is basically a LLM call that uses function calling in a loop. vibeflow can be used to generate the tools for the agent so you don't need to write them.

Function-Calling Agent Example

In this example, we define two tools: add and subtract and we use vibe to generate the agent function. Afterwards, we use the OpenAI API with function calling enabled. After, OpenAI determines which tool to call we can directly use the functions generated by vibe.

from openai import OpenAI
import json
from vibeflow import vibe

client = OpenAI()

@vibe
def add(a: int, b: int) -> int:
    """Add two numbers together and return the result."""
    pass

tools = [{
    "type": "function",
    "function": {
        "name": "add",
        "description": "Add two numbers together and return the result.",
        "parameters": {
            "type": "object",
            "properties": {
                "a": {
                    "type": "number",
                    "description": "First number"
                },
                "b": {
                    "type": "number",
                    "description": "Second number"
                }
            },
            "required": [
                "a",
                "b"
            ],
            "additionalProperties": False
        },
        "strict": True
    }
}]

completion = client.chat.completions.create(
    model="gpt-4.1",
    messages=[{"role": "user", "content": "Add 25 and 17"}],
    tools=tools
)

tool_call = completion.choices[0].message.tool_calls[0]
args = json.loads(tool_call.function.arguments)

result = add(args["a"], args["b"])
print(f"Result of add({args['a']}, {args['b']}) is: {result}")