Getting Started

Quick Start

Two short examples to get you productive: a simple chain with a prompt, model, and parser, and an agent that can call a custom tool.

Basic Chain

This example wires a prompt template to a chat model and a string output parser using the pipe operator.

from educhain.prompts import PromptTemplate
from educhain.models import ChatModel
from educhain.output_parsers import StringOutputParser

model = ChatModel()  # defaults to ChatOpenAI under the hood

prompt = PromptTemplate(
    template="Explain {topic} in simple words.",
    input_variables=["topic"]
)
parser = StringOutputParser()

chain = prompt | model | parser
response = chain.invoke({"topic": "Artificial Intelligence"})
print(response)

Agent with Tools + RAG

Build an agent that can call a custom function as a tool. The same pattern scales to retrieval chains and callback logging.

educhain.py
from educhain.models import ChatModel
from educhain.core.tool import Tool
from educhain.core.agent import Agent

def get_weather(city: str) -> str:
    """Get the current weather for a specific named city."""
    return f"It's sunny in {city}"

weather_tool = Tool(get_weather)
model = ChatModel(tools=[weather_tool])
agent = Agent(model=model)

answer = agent.invoke("What's the weather like in Delhi?")
print(answer)

See demo_agent.py on GitHub for a full example combining Tool Calling, RAG, and Callbacks together.