Skip to main content

A simplified interface for SGR (Schema-Guided Reasoning) agents in LangChain style

Project description

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
  • 🛠️ @tool decorator — turn functions into tools
  • 🤖 ChatOpenAI — LLM wrapper (OpenAI, OpenRouter, etc.)
  • Sync and asyncinvoke() (no await) and ainvoke() (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 with invoke
  • example_structured.py — structured output via output_schema

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easy_sgr-0.1.0.tar.gz (65.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

easy_sgr-0.1.0-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file easy_sgr-0.1.0.tar.gz.

File metadata

  • Download URL: easy_sgr-0.1.0.tar.gz
  • Upload date:
  • Size: 65.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for easy_sgr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bac397c1d3fb14a07075558628534b85764a95e0732cc8fc7891f31dbdc449fb
MD5 21d4085578be7dff8805fb0f296a945a
BLAKE2b-256 31c00df79e84c6d1af74033a52db6a995915f6cc39742877a0a4de7a3e222747

See more details on using hashes here.

File details

Details for the file easy_sgr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: easy_sgr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 53.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for easy_sgr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64bef2c62fbb475fd712a6fb305cd7964555aa17f2c7e655ddaec38e947f8146
MD5 a9ab38549fb7f6bf231a93f081286c36
BLAKE2b-256 2d3977c0158488c1d5089d9d2550fd106e32a21025eed84f96b73025f0424124

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page