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)