Agents
Autonomous Agent
With Autonomous Agents, the LLM can run functions to:
- Search the knowledge base
- Search the chat history
- Achieve other tasks
The LLM decides if it needs to search the knowledge base and what search parameters it needs to query the knowledge base.
from phi.agent import Agent
from phi.knowledge.pdf import PDFUrlKnowledgeBase
from phi.vectordb.pgvector import PgVector
knowledge_base = PDFUrlKnowledgeBase(
urls=["https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"],
vector_db=PgVector(
table_name="recipes",
db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
),
)
# Comment out as the knowledge base is already loaded.
# knowledge_base.load(recreate=False)
agent = Agent(
knowledge=knowledge_base,
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to search the knowledge base
search_knowledge=True,
# Enable the agent to read the chat history
read_chat_history=True,
)
agent.print_response("How do I make pad thai?", markdown=True)
agent.print_response("What was my last question?", markdown=True)
Usage
1
Create a virtual environment
Open the Terminal
and create a python virtual environment.
2
Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v pgvolume:/var/lib/postgresql/data \
-p 5532:5432 \
--name pgvector \
phidata/pgvector:16
3
Install libraries
pip install -U pgvector pypdf "psycopg[binary]" sqlalchemy openai phidata
4
Run the agent
Information
- View on Github
Was this page helpful?