|
1 | | -from abi.services.agent.IntentAgent import ( |
2 | | - IntentAgent, |
3 | | - Intent, |
4 | | - IntentType, |
| 1 | +from abi.services.agent.Agent import ( |
| 2 | + Agent, |
5 | 3 | AgentConfiguration, |
6 | 4 | AgentSharedState, |
| 5 | + MemorySaver, |
7 | 6 | ) |
8 | | -from abi.services.agent.Agent import Agent |
9 | | -from fastapi import APIRouter |
10 | | -from src.core.modules.perplexity.models.perplexity_gpt_4o import model |
11 | 7 | from typing import Optional |
12 | | -from enum import Enum |
13 | | -from abi import logger |
| 8 | +from src.core.modules.perplexity.models.sonar_pro import model |
14 | 9 |
|
15 | | -AVATAR_URL = "https://naasai-public.s3.eu-west-3.amazonaws.com/abi/assets/perplexity.png" |
16 | 10 | NAME = "Perplexity" |
17 | | -TYPE = "core" |
18 | | -SLUG = "perplexity" |
19 | 11 | DESCRIPTION = "Perplexity Agent that provides real-time answers to any question on the web using Perplexity AI." |
20 | | -MODEL = "perplexity-gpt-4o" |
21 | | -SYSTEM_PROMPT = """ |
22 | | -Role: |
23 | | -You are Perplexity, a researcher agent with access to Perplexity AI search engine. |
24 | | -
|
25 | | -Objective: |
26 | | -Provide accurate and comprehensive information to user inquiries using your web search capabilities. |
27 | | -
|
28 | | -Context: |
29 | | -You will receive prompts from users but also from a supervisor agent named 'abi' that already handle the conversation with the user. |
30 | | -When users say things like "ask perplexity", "parler à perplexity", "I want to talk to perplexity", or similar phrases referring to YOU: |
31 | | -- Recognize that YOU ARE Perplexity - don't try to "connect" them to Perplexity |
32 | | -- Respond directly as Perplexity without any delegation confusion |
33 | | -- Simply acknowledge and proceed to help them directly |
34 | | -- Never say "I cannot connect you to Perplexity" - you ARE Perplexity! |
35 | | -
|
36 | | -Tasks: |
37 | | -- Answer the user's question |
38 | | -- If you don't know the answer, you must ask more information to the user or propose to use differents agents to answer the question. |
39 | | -
|
40 | | -Tools: |
41 | | -- current_datetime: Get the current datetime in Paris timezone. |
42 | | -- ask_question: Ask a question to Perplexity AI |
43 | | -
|
44 | | -Operating Guidelines: |
45 | | -1. Get the date and time using current_datetime tool and add it to user's question |
46 | | -For example: |
47 | | -"le gagnant de la dernière ligue des champions masculin" -> "Current datetime: 2025-06-25 10:00:00 : le gagnant de la dernière ligue des champions masculin" |
48 | | -2. Perform the search using Perplexity AI tool: ask_question |
49 | | -3. Present information as found in search results |
50 | | -
|
51 | | -Constraints: |
52 | | -- Must follow the operating guidelines from any prompts you receive |
53 | | -- NEVER use your internal knowledge base to answer questions |
54 | | -- Try to find at least 1 source in the response which is not a link to the Perplexity page. |
55 | | -- Must display sources full URL |
56 | | -- Must format sources as at the end of the response after 2 blank lines: |
57 | | -``` |
58 | | -**Sources:** |
59 | | -- [Source Name](source_url) |
60 | | -``` |
61 | | -
|
62 | | -Examples: |
63 | | -``` |
64 | | -**Sources:** |
65 | | -- [Les echos](https://www.lesechos.fr/entreprises-et-marches/actualites/2025-06-25/) |
66 | | -- [Le Monde](https://www.lemonde.fr/economie/article |
67 | | -- [Le Parisien](https://www.leparisien.fr/economie/article |
68 | | -``` |
69 | | -""" |
70 | | -TEMPERATURE = 0 |
71 | | -DATE = True |
72 | | -INSTRUCTIONS_TYPE = "system" |
73 | | -ONTOLOGY = True |
| 12 | +AVATAR_URL = "https://naasai-public.s3.eu-west-3.amazonaws.com/abi/assets/perplexity.png" |
74 | 13 | SUGGESTIONS: list = [] |
75 | 14 |
|
76 | 15 | def create_agent( |
77 | 16 | agent_shared_state: Optional[AgentSharedState] = None, |
78 | 17 | agent_configuration: Optional[AgentConfiguration] = None |
79 | | -) -> Optional[IntentAgent]: |
80 | | - # Check if model is available |
81 | | - if model is None: |
82 | | - logger.error("Perplexity model not available - missing OpenAI API key and Perplexity API key") |
83 | | - return None |
84 | | - |
| 18 | +) -> Agent: |
| 19 | + # System prompt |
| 20 | + SYSTEM_PROMPT = """ |
| 21 | + Role: |
| 22 | + You are Perplexity, an advanced AI research agent powered by the Perplexity AI search engine. |
| 23 | + You excel at real-time information gathering, fact-checking, and providing up-to-date insights across all fields of knowledge. |
| 24 | +
|
| 25 | + Objective: |
| 26 | + - Deliver comprehensive, well-researched answers by leveraging real-time web search capabilities |
| 27 | + - Synthesize information from multiple reliable sources to provide balanced perspectives |
| 28 | + - Present complex topics in a clear, accessible manner while maintaining accuracy |
| 29 | + - Proactively fact-check information and acknowledge any limitations in available data |
| 30 | + - Include relevant context and background information when beneficial to understanding |
| 31 | +
|
| 32 | + Constraints: |
| 33 | + - You maintain a professional yet approachable tone, always striving for accuracy and clarity in your responses. |
| 34 | + - Only include source references when you have actual URLs to cite |
| 35 | + - When citing sources, place them at the end of your response after two blank lines |
| 36 | + - Format sources exactly as shown in the example below: |
| 37 | +
|
| 38 | + Examples: |
| 39 | + ``` |
| 40 | + **Sources:** |
| 41 | + - [1](https://www.lesechos.fr/entreprises-et-marches/actualites/2025-06-25/) |
| 42 | + - [2](https://www.lemonde.fr/economie/article) |
| 43 | + - [3](https://www.leparisien.fr/economie/article) |
| 44 | + ``` |
| 45 | + """ |
85 | 46 | # Set configuration |
86 | 47 | if agent_configuration is None: |
87 | 48 | agent_configuration = AgentConfiguration( |
88 | 49 | system_prompt=SYSTEM_PROMPT, |
89 | 50 | ) |
90 | 51 | if agent_shared_state is None: |
91 | 52 | agent_shared_state = AgentSharedState(thread_id="0") |
92 | | - |
93 | | - |
94 | | - # Init |
95 | | - from langchain_core.tools import Tool |
96 | | - from typing import List, Union |
97 | | - |
98 | | - tools: List[Union[Tool, Agent]] = [] |
99 | | - |
100 | | - from src import secret |
101 | | - from src.core.modules.perplexity.integrations import PerplexityIntegration |
102 | | - from src.core.modules.perplexity.integrations.PerplexityIntegration import PerplexityIntegrationConfiguration |
103 | | - |
104 | | - perplexity_api_key = secret.get('PERPLEXITY_API_KEY') |
105 | | - if perplexity_api_key is not None: |
106 | | - perplexity_integration_configuration = PerplexityIntegrationConfiguration( |
107 | | - api_key=perplexity_api_key |
108 | | - ) |
109 | | - tools += PerplexityIntegration.as_tools(perplexity_integration_configuration) |
110 | | - else: |
111 | | - logger.error("Perplexity model not available - missing Perplexity API key") |
112 | | - return None |
113 | | - |
114 | | - from datetime import datetime |
115 | | - from zoneinfo import ZoneInfo |
116 | | - from langchain_core.tools import StructuredTool |
117 | | - from pydantic import BaseModel |
118 | | - |
119 | | - class EmptySchema(BaseModel): |
120 | | - pass |
121 | | - |
122 | | - current_datetime_tool = StructuredTool( |
123 | | - name="current_datetime", |
124 | | - description="Get the current datetime in Paris timezone.", |
125 | | - func=lambda : datetime.now(tz=ZoneInfo('Europe/Paris')), |
126 | | - args_schema=EmptySchema |
127 | | - ) |
128 | | - |
129 | | - from typing import cast |
130 | | - tools += [cast(Tool, current_datetime_tool)] |
131 | | - |
132 | | - intents: list = [ |
133 | | - Intent( |
134 | | - intent_value="what is your name", |
135 | | - intent_type=IntentType.RAW, |
136 | | - intent_target="I am Perplexity, an AI research assistant that provides real-time answers using web search capabilities.", |
137 | | - ), |
138 | | - Intent( |
139 | | - intent_value="what can you do", |
140 | | - intent_type=IntentType.RAW, |
141 | | - intent_target="I can search the web in real-time, provide up-to-date information, research any topic, and answer questions using the latest information from the internet.", |
142 | | - ), |
143 | | - ] |
144 | 53 |
|
145 | 54 | return PerplexityAgent( |
146 | 55 | name=NAME, |
147 | 56 | description=DESCRIPTION, |
148 | | - chat_model=model.model, |
149 | | - tools=tools, |
| 57 | + chat_model=model, |
| 58 | + tools=[], |
150 | 59 | agents=[], |
151 | | - intents=intents, |
152 | 60 | state=agent_shared_state, |
153 | 61 | configuration=agent_configuration, |
154 | | - memory=None |
| 62 | + memory=MemorySaver() |
155 | 63 | ) |
156 | 64 |
|
157 | | -class PerplexityAgent(IntentAgent): |
158 | | - def as_api( |
159 | | - self, |
160 | | - router: APIRouter, |
161 | | - route_name: str = NAME, |
162 | | - name: str = NAME.replace("_", " "), |
163 | | - description: str = "API endpoints to call the Perplexity agent completion.", |
164 | | - description_stream: str = "API endpoints to call the Perplexity agent stream completion.", |
165 | | - tags: Optional[list[str | Enum]] = None, |
166 | | - ) -> None: |
167 | | - if tags is None: |
168 | | - tags = [] |
169 | | - return super().as_api( |
170 | | - router, route_name, name, description, description_stream, tags |
171 | | - ) |
| 65 | +class PerplexityAgent(Agent): |
| 66 | + pass |
0 commit comments