Skip to content

Commit

Permalink
v2.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ashpreetbedi committed Oct 16, 2024
1 parent 110d26c commit c309a5e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
58 changes: 58 additions & 0 deletions agents/web_search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from textwrap import dedent
from typing import Optional

from phi.agent import Agent
from phi.model.openai import OpenAIChat
from phi.tools.serpapi_tools import SerpApiTools

from agents.settings import agent_settings
from phi.storage.agent.postgres import PgAgentStorage

from db.session import db_url

web_search_agent_storage = PgAgentStorage(table_name="web_search_agent", db_url=db_url)


def get_web_search_agent(
user_id: Optional[str] = None,
session_id: Optional[str] = None,
debug_mode: bool = False,
) -> Agent:
return Agent(
name="Web Search Agent",
agent_id="web-search-agent",
role="Search the web for information",
session_id=session_id,
user_id=user_id,
model=OpenAIChat(
model=agent_settings.gpt_4,
max_tokens=agent_settings.default_max_completion_tokens,
temperature=agent_settings.default_temperature,
),
tools=[SerpApiTools()],
description="You are a Web Search Agent that has the special skill of searching the web for information.",
instructions=[
"If you can directly answer the user's question, do so.",
"Otherwise, search the web for information.",
"Important: \n"
" - Focus on legitimate sources",
" - Always provide sources and the links to the information you used to answer the question",
" - If you cannot find the answer, say so and ask the user to provide more details.",
],
expected_output=dedent("""\
Your answer should be in the following format:
## Answer
{provide a detailed answer to the user's question}
## Sources
{provide the sources and links to the information you used to answer the question}
"""),
markdown=True,
add_history_to_messages=True,
add_datetime_to_instructions=True,
storage=web_search_agent_storage,
# Enable monitoring on phidata.app
monitoring=True,
debug_mode=debug_mode,
)
4 changes: 3 additions & 1 deletion api/routes/playground.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

from agents.finance import get_finance_agent
from agents.research import get_research_agent
from agents.web_search import get_web_search_agent

######################################################
## Router for the agent playground
######################################################

finance_agent = get_finance_agent(debug_mode=True)
research_agent = get_research_agent(debug_mode=True)
web_search_agent = get_web_search_agent(debug_mode=True)

# Create a playground instance
playground = Playground(agents=[finance_agent, research_agent])
playground = Playground(agents=[finance_agent, research_agent, web_search_agent])
# Log the playground endpoint with phidata.app
if getenv("RUNTIME_ENV") == "dev":
playground.create_endpoint("http://localhost:8000")
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies = [
"nest_asyncio",
"openai",
"pgvector",
"phidata[aws]==2.5.2",
"phidata[aws]==2.5.3",
"pillow",
"psycopg[binary]",
"pypdf",
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ packaging==24.1
pandas==2.2.3
peewee==3.17.7
pgvector==0.3.5
phidata==2.5.2
phidata==2.5.3
pillow==11.0.0
platformdirs==4.3.6
pluggy==1.5.0
Expand Down

0 comments on commit c309a5e

Please sign in to comment.