from definable.model.openai import OpenAIChatfrom definable.model.message import Messagemodel = OpenAIChat(id="gpt-4o")response = model.invoke( messages=[Message(role="user", content="What is the capital of France?")], assistant_message=Message(role="assistant", content=""),)print(response.content)
from definable.agent import Agentfrom definable.tool.decorator import tool@tooldef get_weather(city: str) -> str: """Get the current weather for a city.""" return f"The weather in {city} is sunny, 72F."agent = Agent( model="gpt-4o", tools=[get_weather], instructions="You are a helpful weather assistant.",)output = agent.run("What's the weather in San Francisco?")print(output.content)
from definable.agent import Agentfrom definable.knowledge import Knowledgefrom definable.vectordb import InMemoryVectorDBknowledge = Knowledge(vector_db=InMemoryVectorDB())knowledge.add("Definable supports 10 LLM providers including OpenAI and Anthropic.")knowledge.add("Agents can use tools, knowledge, memory, and middleware.")agent = Agent( model="gpt-4o", knowledge=knowledge, instructions="Answer questions using the provided knowledge.",)output = agent.run("What LLM providers does Definable support?")print(output.content)
Give the agent persistent memory across conversations:
from definable.agent import Agentfrom definable.memory import Memory, SQLiteStoreagent = Agent( model="gpt-4o", instructions="You are a helpful assistant with memory.", memory=Memory(store=SQLiteStore("./memory.db")),)output = agent.run("My name is Alice and I work at Acme.", user_id="alice")output = agent.run("Where do I work?", user_id="alice")print(output.content) # "You work at Acme."
from definable.agent import Agentagent = Agent(model="gpt-4o", instructions="You are a helpful assistant.")for event in agent.run_stream("Tell me a story about AI."): if event.event == "RunContent" and event.content: print(event.content, end="", flush=True)