Hello, OpenSymbolicAI
The five-minute first win: install the framework, point it at a local model, write a three-primitive agent, and watch it plan and execute.
Before you start
The five-minute first win: a working agent that plans and executes a small
arithmetic task. The finished project is two files: calculator.py (the agent)
and main.py (runs it).
If you cloned tutorials-py in the prerequisites, the code is already on your
machine. cd in and run it:
cd tutorials-py/01-hello
uv run main.pyOr follow the steps below to build it from scratch.
1. Install#
Create a new project and add the dependency:
mkdir 01-hello && cd 01-hello
uv init
uv add opensymbolicai-core2. Write a three-primitive agent#
A primitive is the core building block: a typed, documented method the planner
is allowed to call. The base class PlanExecute turns a written task into a
plan and executes it.
# calculator.py
from opensymbolicai.blueprints import PlanExecute
from opensymbolicai.core import primitive
class Calculator(PlanExecute):
"""A tiny calculator agent with three primitives."""
@primitive(read_only=True)
def add(self, a: float, b: float) -> float:
"""Add two numbers."""
return a + b
@primitive(read_only=True)
def multiply(self, a: float, b: float) -> float:
"""Multiply two numbers."""
return a * b
@primitive(read_only=True)
def subtract(self, a: float, b: float) -> float:
"""Subtract b from a."""
return a - bThe type annotations are the model's contract, and the docstrings are its
guidance. You'll learn what read_only does in Track 2.
3. Run it#
Point the agent at a local model and give it a task in plain English:
# main.py
from calculator import Calculator
from opensymbolicai.llm import LLMConfig
llm = LLMConfig(provider="ollama", model="qwen2.5-coder:7b")
agent = Calculator(llm=llm)
result = agent.run("what is 7 times 8 minus 3")
print(result.result) # 53uv run main.py4. What just happened#
The model didn't do the arithmetic. It wrote a plan, a small program like
result = subtract(multiply(7, 8), 3), and your primitives ran it in plain
Python in your own process.
The numbers never went into a follow-up prompt. The model wrote the plan once, and your primitives produced the values.