feat(pyproject): add psycopg dependency for PostgreSQL support

- 在依赖项中添加psycopg[binary]以支持PostgreSQL
- 提高项目与PostgreSQL的兼容性和灵活性

 feat(test2): create pdf_agent CLI application

- 添加pdf_agent函数以实现PDF代理功能
- 允许用户通过命令行界面与代理交互
This commit is contained in:
2025-03-31 03:38:50 +08:00
parent 6d25886286
commit 46efa8d9ed
3 changed files with 98 additions and 0 deletions

48
test2.py Normal file
View File

@@ -0,0 +1,48 @@
import typer
from typing import Optional, List
from agno.agent import Agent
from agno.storage.sqlite import SqliteStorage
from agno.storage.postgres import PostgresStorage
storage =SqliteStorage(table_name="agent_sessions", db_file="tmp/agent_storage.db")
# db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
# storage = PostgresStorage(table_name="pdf_agent", db_url=db_url)
def pdf_agent(new: bool = False, user: str = "user"):
session_id: Optional[str] = None
if not new:
existing_sessions: List[str] = storage.get_all_session_ids(user)
if len(existing_sessions) > 0:
session_id = existing_sessions[0]
agent = Agent(
session_id=session_id,
user_id=user,
#knowledge=knowledge_base,
storage=storage,
# Show tool calls in the response
show_tool_calls=True,
# Enable the agent to read the chat history
read_chat_history=True,
# We can also automatically add the chat history to the messages sent to the model
# But giving the model the chat history is not always useful, so we give it a tool instead
# to only use when needed.
# add_history_to_messages=True,
# Number of historical responses to add to the messages.
# num_history_responses=3,
)
if session_id is None:
session_id = agent.session_id
print(f"Started Session: {session_id}\n")
else:
print(f"Continuing Session: {session_id}\n")
# Runs the agent as a cli app
agent.cli_app(markdown=True)
if __name__ == "__main__":
# Load the knowledge base: Comment after first run
#knowledge_base.load(upsert=True)
typer.run(pdf_agent)