Skip to main content
Create an agent that retrieves relevant information from a knowledge base before answering.
1

Create the agent

agent_knowledge.py
from definable.agent import Agent
from definable.knowledge import Knowledge
from definable.vectordb import InMemoryVectorDB

knowledge = Knowledge(vector_db=InMemoryVectorDB())
knowledge.add("Definable supports 10 LLM providers: OpenAI, Anthropic, Google, DeepSeek, Mistral, Moonshot, xAI, Perplexity, Ollama, and OpenRouter.")
knowledge.add("Agents can use tools, knowledge, memory, middleware, and tracing.")
knowledge.add("The @tool decorator converts Python functions into agent-callable tools.")

agent = Agent(
    model="gpt-4o",
    knowledge=knowledge,
    instructions="Answer questions using the provided knowledge base. Cite specific facts.",
)

output = agent.run("What LLM providers does Definable support?")
print(output.content)
2

Install dependencies

pip install definable
3

Export your API key

export OPENAI_API_KEY=sk-***
4

Run

python agent_knowledge.py
The agent retrieves the most relevant documents and uses them to answer accurately.
You can also use path shorthand to load an entire directory:
agent = Agent(model="gpt-4o", knowledge="./docs/")
This auto-configures InMemoryVectorDB + OpenAIEmbedder + RecursiveChunker and loads all supported files from the directory.