Easy SGR
A simplified interface for building SGR (Schema-Guided Reasoning) agents in a LangChain-like style.
Features
- 🎯 Simple API in the spirit of LangChain
- 🛠️
@tooldecorator — turn functions into tools - 🤖 ChatOpenAI — LLM wrapper (OpenAI, OpenRouter, etc.)
- ⚡ Sync and async —
invoke()(no await) andainvoke()(with await) - 📐 Structured output — Pydantic schema via
output_schema - 🔧 Flexible agent configuration
Installation
pip install -e .
Or from PyPI (after publishing):
pip install easy-sgr
Quick start
1. Tools
The @tool decorator turns a function into an SGR tool:
from easy_sgr import tool
@tool
def add_numbers(a: int, b: int) -> int:
"""Adds two numbers together.
Args:
a: First number
b: Second number
"""
return a + b
@tool
async def get_weather(city: str) -> str:
"""Get weather for a city."""
return f"Weather in {city}: Sunny"
2. LLM
from easy_sgr import ChatOpenAI
llm = ChatOpenAI(
model="gpt-4o-mini",
temperature=0,
api_key="your-api-key",
base_url="https://api.openai.com/v1",
)
3. Agent and run
from easy_sgr import create_agent
tools = [add_numbers, get_weather]
messages = [
{"role": "system", "content": "You are a helpful assistant."},
]
agent = create_agent(llm=llm, tools=tools, messages=messages)
# Sync (no await)
result = agent.invoke({"input": "What is 10 + 5?"})
print(result["output"])
# Async (inside async code)
result = await agent.ainvoke({"input": "What is 10 + 5?"})
print(result["output"])
Full example
import os
from dotenv import load_dotenv
from easy_sgr import tool, ChatOpenAI, create_agent
load_dotenv()
@tool
def add_numbers(a: int, b: int) -> int:
"""Adds two numbers together."""
return a + b
llm = ChatOpenAI(
model=os.getenv("OPENAI_MODEL", "gpt-4o-mini"),
temperature=0,
api_key=os.getenv("OPENAI_API_KEY"),
base_url=os.getenv("OPENAI_BASE_URL"),
)
agent = create_agent(
llm=llm,
tools=[add_numbers],
messages=[{"role": "system", "content": "You are a helpful assistant."}],
)
result = agent.invoke({"input": "What is 10 + 5?"})
print(result["output"])
Structured output (output_schema)
Pass a Pydantic model as output_schema — the agent will return an instance of it:
from pydantic import BaseModel, Field
from easy_sgr import create_agent, tool, ChatOpenAI
class MathResult(BaseModel):
sum_result: int = Field(description="Result of addition")
product_result: int = Field(description="Result of multiplication")
summary: str = Field(description="Brief summary")
@tool
def add_numbers(a: int, b: int) -> int:
"""Adds two numbers."""
return a + b
@tool
def multiply_numbers(a: int, b: int) -> int:
"""Multiplies two numbers."""
return a * b
agent = create_agent(
llm=llm,
tools=[add_numbers, multiply_numbers],
messages=[{"role": "system", "content": "..."}],
output_schema=MathResult,
)
result = agent.invoke({"input": "Calculate 10 + 5 and 10 * 5, then summarize."})
output = result["output"] # MathResult
print(output.sum_result, output.product_result, output.summary)
Examples
See the examples/ folder:
example.py— basic usage withinvokeexample_structured.py— structured output viaoutput_schema
Metadata
Release files for easy-sgr 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| easy_sgr-0.1.0.tar.gz | 65.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| easy_sgr-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 118.6 kB
Release files / easy_sgr-0.1.0.tar.gz
| Download URL | easy_sgr-0.1.0.tar.gz |
|---|---|
| Size | 65.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bac397c1d3fb14a07075558628534b85764a95e0732cc8fc7891f31dbdc449fb
|
|
BLAKE2b-256 checksum How to use checksums |
31c00df79e84c6d1af74033a52db6a995915f6cc39742877a0a4de7a3e222747
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|
Release files / easy_sgr-0.1.0-py3-none-any.whl
| Download URL | easy_sgr-0.1.0-py3-none-any.whl |
|---|---|
| Size | 53.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64bef2c62fbb475fd712a6fb305cd7964555aa17f2c7e655ddaec38e947f8146
|
|
BLAKE2b-256 checksum How to use checksums |
2d3977c0158488c1d5089d9d2550fd106e32a21025eed84f96b73025f0424124
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.3
|