atendentepro 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- atendentepro/README.md +890 -0
- atendentepro/__init__.py +215 -0
- atendentepro/agents/__init__.py +45 -0
- atendentepro/agents/answer.py +62 -0
- atendentepro/agents/confirmation.py +69 -0
- atendentepro/agents/flow.py +64 -0
- atendentepro/agents/interview.py +68 -0
- atendentepro/agents/knowledge.py +296 -0
- atendentepro/agents/onboarding.py +65 -0
- atendentepro/agents/triage.py +57 -0
- atendentepro/agents/usage.py +56 -0
- atendentepro/config/__init__.py +19 -0
- atendentepro/config/settings.py +134 -0
- atendentepro/guardrails/__init__.py +21 -0
- atendentepro/guardrails/manager.py +419 -0
- atendentepro/license.py +502 -0
- atendentepro/models/__init__.py +21 -0
- atendentepro/models/context.py +21 -0
- atendentepro/models/outputs.py +118 -0
- atendentepro/network.py +325 -0
- atendentepro/prompts/__init__.py +35 -0
- atendentepro/prompts/answer.py +114 -0
- atendentepro/prompts/confirmation.py +124 -0
- atendentepro/prompts/flow.py +112 -0
- atendentepro/prompts/interview.py +123 -0
- atendentepro/prompts/knowledge.py +135 -0
- atendentepro/prompts/onboarding.py +146 -0
- atendentepro/prompts/triage.py +42 -0
- atendentepro/templates/__init__.py +51 -0
- atendentepro/templates/manager.py +530 -0
- atendentepro/utils/__init__.py +19 -0
- atendentepro/utils/openai_client.py +154 -0
- atendentepro/utils/tracing.py +71 -0
- atendentepro-0.3.0.dist-info/METADATA +306 -0
- atendentepro-0.3.0.dist-info/RECORD +39 -0
- atendentepro-0.3.0.dist-info/WHEEL +5 -0
- atendentepro-0.3.0.dist-info/entry_points.txt +2 -0
- atendentepro-0.3.0.dist-info/licenses/LICENSE +25 -0
- atendentepro-0.3.0.dist-info/top_level.txt +1 -0
atendentepro/network.py
ADDED
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Agent Network for AtendentePro.
|
|
4
|
+
|
|
5
|
+
Provides functions to create and configure the agent network with proper handoffs.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any, Callable, Dict, List, Literal, Optional
|
|
13
|
+
|
|
14
|
+
from atendentepro.agents import (
|
|
15
|
+
create_triage_agent,
|
|
16
|
+
create_flow_agent,
|
|
17
|
+
create_interview_agent,
|
|
18
|
+
create_answer_agent,
|
|
19
|
+
create_knowledge_agent,
|
|
20
|
+
create_confirmation_agent,
|
|
21
|
+
create_usage_agent,
|
|
22
|
+
create_onboarding_agent,
|
|
23
|
+
TriageAgent,
|
|
24
|
+
FlowAgent,
|
|
25
|
+
InterviewAgent,
|
|
26
|
+
AnswerAgent,
|
|
27
|
+
KnowledgeAgent,
|
|
28
|
+
ConfirmationAgent,
|
|
29
|
+
UsageAgent,
|
|
30
|
+
OnboardingAgent,
|
|
31
|
+
)
|
|
32
|
+
from atendentepro.guardrails import get_guardrails_for_agent, set_guardrails_client
|
|
33
|
+
from atendentepro.license import require_activation
|
|
34
|
+
from atendentepro.templates import (
|
|
35
|
+
TemplateManager,
|
|
36
|
+
configure_template_manager,
|
|
37
|
+
load_flow_config,
|
|
38
|
+
load_interview_config,
|
|
39
|
+
load_triage_config,
|
|
40
|
+
load_knowledge_config,
|
|
41
|
+
load_confirmation_config,
|
|
42
|
+
load_onboarding_config,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@dataclass
|
|
47
|
+
class AgentNetwork:
|
|
48
|
+
"""
|
|
49
|
+
Container for all agents in the network.
|
|
50
|
+
|
|
51
|
+
Provides access to individual agents and methods to configure
|
|
52
|
+
the network for different clients.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
triage: Optional[TriageAgent] = None
|
|
56
|
+
flow: Optional[FlowAgent] = None
|
|
57
|
+
interview: Optional[InterviewAgent] = None
|
|
58
|
+
answer: Optional[AnswerAgent] = None
|
|
59
|
+
knowledge: Optional[KnowledgeAgent] = None
|
|
60
|
+
confirmation: Optional[ConfirmationAgent] = None
|
|
61
|
+
usage: Optional[UsageAgent] = None
|
|
62
|
+
onboarding: Optional[OnboardingAgent] = None
|
|
63
|
+
|
|
64
|
+
templates_root: Optional[Path] = None
|
|
65
|
+
current_client: str = "standard"
|
|
66
|
+
|
|
67
|
+
def get_all_agents(self) -> List:
|
|
68
|
+
"""Get list of all configured agents."""
|
|
69
|
+
agents = []
|
|
70
|
+
for attr in ["triage", "flow", "interview", "answer", "knowledge",
|
|
71
|
+
"confirmation", "usage", "onboarding"]:
|
|
72
|
+
agent = getattr(self, attr, None)
|
|
73
|
+
if agent:
|
|
74
|
+
agents.append(agent)
|
|
75
|
+
return agents
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def create_standard_network(
|
|
79
|
+
templates_root: Path,
|
|
80
|
+
client: str = "standard",
|
|
81
|
+
include_onboarding: bool = False,
|
|
82
|
+
custom_tools: Optional[Dict[str, List]] = None,
|
|
83
|
+
) -> AgentNetwork:
|
|
84
|
+
"""
|
|
85
|
+
Create a standard agent network with proper handoff configuration.
|
|
86
|
+
|
|
87
|
+
This creates the default network configuration with:
|
|
88
|
+
- Triage -> Flow, Confirmation, Knowledge, Usage
|
|
89
|
+
- Flow -> Interview, Triage
|
|
90
|
+
- Interview -> Answer
|
|
91
|
+
- Answer -> Triage, Interview
|
|
92
|
+
- Confirmation -> Triage
|
|
93
|
+
- Knowledge -> Triage
|
|
94
|
+
- Usage -> Triage
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
templates_root: Root directory for template configurations.
|
|
98
|
+
client: Client key to load configurations for.
|
|
99
|
+
include_onboarding: Whether to include the onboarding agent.
|
|
100
|
+
custom_tools: Optional dict of custom tools by agent name.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
Configured AgentNetwork instance.
|
|
104
|
+
|
|
105
|
+
Raises:
|
|
106
|
+
LicenseNotActivatedError: If the library is not activated.
|
|
107
|
+
"""
|
|
108
|
+
# Verificar licença
|
|
109
|
+
require_activation()
|
|
110
|
+
|
|
111
|
+
# Configure template manager
|
|
112
|
+
manager = configure_template_manager(templates_root, default_client=client)
|
|
113
|
+
|
|
114
|
+
# Load configurations
|
|
115
|
+
try:
|
|
116
|
+
flow_config = load_flow_config(client)
|
|
117
|
+
flow_template = flow_config.get_flow_template()
|
|
118
|
+
flow_keywords = flow_config.get_flow_keywords()
|
|
119
|
+
except FileNotFoundError:
|
|
120
|
+
flow_template = ""
|
|
121
|
+
flow_keywords = ""
|
|
122
|
+
|
|
123
|
+
try:
|
|
124
|
+
interview_config = load_interview_config(client)
|
|
125
|
+
interview_questions = interview_config.interview_questions
|
|
126
|
+
except FileNotFoundError:
|
|
127
|
+
interview_questions = ""
|
|
128
|
+
|
|
129
|
+
try:
|
|
130
|
+
triage_config = load_triage_config(client)
|
|
131
|
+
triage_keywords = triage_config.get_keywords_text()
|
|
132
|
+
except FileNotFoundError:
|
|
133
|
+
triage_keywords = ""
|
|
134
|
+
|
|
135
|
+
try:
|
|
136
|
+
knowledge_config = load_knowledge_config(client)
|
|
137
|
+
knowledge_about = knowledge_config.about
|
|
138
|
+
knowledge_template = knowledge_config.template
|
|
139
|
+
knowledge_format = knowledge_config.format
|
|
140
|
+
embeddings_path = (
|
|
141
|
+
Path(knowledge_config.embeddings_path)
|
|
142
|
+
if knowledge_config.embeddings_path
|
|
143
|
+
else None
|
|
144
|
+
)
|
|
145
|
+
data_sources_description = knowledge_config.get_data_source_description()
|
|
146
|
+
has_embeddings = knowledge_config.has_documents()
|
|
147
|
+
except FileNotFoundError:
|
|
148
|
+
knowledge_about = ""
|
|
149
|
+
knowledge_template = ""
|
|
150
|
+
knowledge_format = ""
|
|
151
|
+
embeddings_path = None
|
|
152
|
+
data_sources_description = ""
|
|
153
|
+
has_embeddings = False
|
|
154
|
+
|
|
155
|
+
try:
|
|
156
|
+
confirmation_config = load_confirmation_config(client)
|
|
157
|
+
confirmation_about = confirmation_config.about
|
|
158
|
+
confirmation_template = confirmation_config.template
|
|
159
|
+
confirmation_format = confirmation_config.format
|
|
160
|
+
except FileNotFoundError:
|
|
161
|
+
confirmation_about = ""
|
|
162
|
+
confirmation_template = ""
|
|
163
|
+
confirmation_format = ""
|
|
164
|
+
|
|
165
|
+
# Load guardrails
|
|
166
|
+
try:
|
|
167
|
+
set_guardrails_client(client, templates_root=templates_root)
|
|
168
|
+
except FileNotFoundError:
|
|
169
|
+
pass
|
|
170
|
+
|
|
171
|
+
# Get custom tools
|
|
172
|
+
tools = custom_tools or {}
|
|
173
|
+
|
|
174
|
+
# Create agents without handoffs first
|
|
175
|
+
triage = create_triage_agent(
|
|
176
|
+
keywords_text=triage_keywords,
|
|
177
|
+
guardrails=get_guardrails_for_agent("Triage Agent", templates_root),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
flow = create_flow_agent(
|
|
181
|
+
flow_template=flow_template,
|
|
182
|
+
flow_keywords=flow_keywords,
|
|
183
|
+
guardrails=get_guardrails_for_agent("Flow Agent", templates_root),
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
interview = create_interview_agent(
|
|
187
|
+
interview_template=flow_template,
|
|
188
|
+
interview_questions=interview_questions,
|
|
189
|
+
tools=tools.get("interview", []),
|
|
190
|
+
guardrails=get_guardrails_for_agent("Interview Agent", templates_root),
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
answer = create_answer_agent(
|
|
194
|
+
answer_template="",
|
|
195
|
+
guardrails=get_guardrails_for_agent("Answer Agent", templates_root),
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
knowledge = create_knowledge_agent(
|
|
199
|
+
knowledge_about=knowledge_about,
|
|
200
|
+
knowledge_template=knowledge_template,
|
|
201
|
+
knowledge_format=knowledge_format,
|
|
202
|
+
embeddings_path=embeddings_path,
|
|
203
|
+
data_sources_description=data_sources_description,
|
|
204
|
+
include_rag_tool=has_embeddings,
|
|
205
|
+
tools=tools.get("knowledge", []),
|
|
206
|
+
guardrails=get_guardrails_for_agent("Knowledge Agent", templates_root),
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
confirmation = create_confirmation_agent(
|
|
210
|
+
confirmation_about=confirmation_about,
|
|
211
|
+
confirmation_template=confirmation_template,
|
|
212
|
+
confirmation_format=confirmation_format,
|
|
213
|
+
guardrails=get_guardrails_for_agent("Confirmation Agent", templates_root),
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
usage = create_usage_agent(
|
|
217
|
+
guardrails=get_guardrails_for_agent("Usage Agent", templates_root),
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
# Configure handoffs
|
|
221
|
+
triage.handoffs = [flow, confirmation, knowledge, usage]
|
|
222
|
+
flow.handoffs = [interview, triage]
|
|
223
|
+
confirmation.handoffs = [triage]
|
|
224
|
+
knowledge.handoffs = [triage]
|
|
225
|
+
usage.handoffs = [triage]
|
|
226
|
+
interview.handoffs = [answer]
|
|
227
|
+
answer.handoffs = [triage, interview]
|
|
228
|
+
|
|
229
|
+
network = AgentNetwork(
|
|
230
|
+
triage=triage,
|
|
231
|
+
flow=flow,
|
|
232
|
+
interview=interview,
|
|
233
|
+
answer=answer,
|
|
234
|
+
knowledge=knowledge,
|
|
235
|
+
confirmation=confirmation,
|
|
236
|
+
usage=usage,
|
|
237
|
+
templates_root=templates_root,
|
|
238
|
+
current_client=client,
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
# Add onboarding if requested
|
|
242
|
+
if include_onboarding:
|
|
243
|
+
try:
|
|
244
|
+
onboarding_config = load_onboarding_config(client)
|
|
245
|
+
from atendentepro.prompts.onboarding import OnboardingField as PromptField
|
|
246
|
+
|
|
247
|
+
fields = [
|
|
248
|
+
PromptField(
|
|
249
|
+
name=f.name,
|
|
250
|
+
prompt=f.prompt,
|
|
251
|
+
priority=f.priority,
|
|
252
|
+
)
|
|
253
|
+
for f in onboarding_config.required_fields
|
|
254
|
+
]
|
|
255
|
+
except FileNotFoundError:
|
|
256
|
+
fields = []
|
|
257
|
+
|
|
258
|
+
onboarding = create_onboarding_agent(
|
|
259
|
+
required_fields=fields,
|
|
260
|
+
tools=tools.get("onboarding", []),
|
|
261
|
+
guardrails=get_guardrails_for_agent("Onboarding Agent", templates_root),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
network.onboarding = onboarding
|
|
265
|
+
onboarding.handoffs = [triage]
|
|
266
|
+
|
|
267
|
+
return network
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def create_custom_network(
|
|
271
|
+
templates_root: Path,
|
|
272
|
+
client: str,
|
|
273
|
+
network_config: Dict[str, List[str]],
|
|
274
|
+
custom_tools: Optional[Dict[str, List]] = None,
|
|
275
|
+
) -> AgentNetwork:
|
|
276
|
+
"""
|
|
277
|
+
Create a custom agent network with specified handoff configuration.
|
|
278
|
+
|
|
279
|
+
Args:
|
|
280
|
+
templates_root: Root directory for template configurations.
|
|
281
|
+
client: Client key to load configurations for.
|
|
282
|
+
network_config: Dict mapping agent names to list of handoff agent names.
|
|
283
|
+
custom_tools: Optional dict of custom tools by agent name.
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
Configured AgentNetwork instance.
|
|
287
|
+
|
|
288
|
+
Raises:
|
|
289
|
+
LicenseNotActivatedError: If the library is not activated.
|
|
290
|
+
"""
|
|
291
|
+
# Verificar licença (já é feito em create_standard_network, mas verificamos novamente)
|
|
292
|
+
require_activation()
|
|
293
|
+
|
|
294
|
+
# First create the standard network
|
|
295
|
+
network = create_standard_network(
|
|
296
|
+
templates_root=templates_root,
|
|
297
|
+
client=client,
|
|
298
|
+
include_onboarding="onboarding" in network_config,
|
|
299
|
+
custom_tools=custom_tools,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
# Map agent names to instances
|
|
303
|
+
agent_map = {
|
|
304
|
+
"triage": network.triage,
|
|
305
|
+
"flow": network.flow,
|
|
306
|
+
"interview": network.interview,
|
|
307
|
+
"answer": network.answer,
|
|
308
|
+
"knowledge": network.knowledge,
|
|
309
|
+
"confirmation": network.confirmation,
|
|
310
|
+
"usage": network.usage,
|
|
311
|
+
"onboarding": network.onboarding,
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
# Apply custom handoff configuration
|
|
315
|
+
for agent_name, handoff_names in network_config.items():
|
|
316
|
+
agent = agent_map.get(agent_name)
|
|
317
|
+
if agent:
|
|
318
|
+
handoffs = [
|
|
319
|
+
agent_map[h] for h in handoff_names
|
|
320
|
+
if h in agent_map and agent_map[h] is not None
|
|
321
|
+
]
|
|
322
|
+
agent.handoffs = handoffs
|
|
323
|
+
|
|
324
|
+
return network
|
|
325
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Prompts module for AtendentePro library."""
|
|
3
|
+
|
|
4
|
+
from .triage import get_triage_prompt, TRIAGE_INTRO
|
|
5
|
+
from .flow import get_flow_prompt, FlowPromptBuilder
|
|
6
|
+
from .interview import get_interview_prompt, InterviewPromptBuilder
|
|
7
|
+
from .answer import get_answer_prompt, AnswerPromptBuilder
|
|
8
|
+
from .knowledge import get_knowledge_prompt, KnowledgePromptBuilder
|
|
9
|
+
from .confirmation import get_confirmation_prompt, ConfirmationPromptBuilder
|
|
10
|
+
from .onboarding import get_onboarding_prompt, OnboardingPromptBuilder
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
# Triage
|
|
14
|
+
"get_triage_prompt",
|
|
15
|
+
"TRIAGE_INTRO",
|
|
16
|
+
# Flow
|
|
17
|
+
"get_flow_prompt",
|
|
18
|
+
"FlowPromptBuilder",
|
|
19
|
+
# Interview
|
|
20
|
+
"get_interview_prompt",
|
|
21
|
+
"InterviewPromptBuilder",
|
|
22
|
+
# Answer
|
|
23
|
+
"get_answer_prompt",
|
|
24
|
+
"AnswerPromptBuilder",
|
|
25
|
+
# Knowledge
|
|
26
|
+
"get_knowledge_prompt",
|
|
27
|
+
"KnowledgePromptBuilder",
|
|
28
|
+
# Confirmation
|
|
29
|
+
"get_confirmation_prompt",
|
|
30
|
+
"ConfirmationPromptBuilder",
|
|
31
|
+
# Onboarding
|
|
32
|
+
"get_onboarding_prompt",
|
|
33
|
+
"OnboardingPromptBuilder",
|
|
34
|
+
]
|
|
35
|
+
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Answer Agent prompts."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class AnswerPromptBuilder:
|
|
12
|
+
"""Builder for Answer Agent prompts."""
|
|
13
|
+
|
|
14
|
+
answer_template: str = ""
|
|
15
|
+
|
|
16
|
+
def build(self) -> str:
|
|
17
|
+
"""Build the complete answer agent prompt."""
|
|
18
|
+
return get_answer_prompt(answer_template=self.answer_template)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
ANSWER_INTRO = """
|
|
22
|
+
Você é um agente de resposta especializado.
|
|
23
|
+
Você deverá responder à pergunta do usuário usando o template de resposta configurado.
|
|
24
|
+
Use as informações coletadas durante a entrevista para fornecer uma resposta precisa e útil.
|
|
25
|
+
Se precisar de mais informações, transfira para o interview_agent com orientações objetivas.
|
|
26
|
+
Sempre que concluir uma resposta válida ao usuário, assim que receber qualquer outra pergunta, transfira a conversa para o triage_agent.
|
|
27
|
+
Nas mensagens ao usuário, utilize linguagem natural e evite revelar processos internos, etapas de análise ou nomes de agentes.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
ANSWER_MODULES = """
|
|
31
|
+
Deve seguir as seguintes etapas de forma sequencial (todas são raciocínio interno; não exponha nada ao usuário):
|
|
32
|
+
[READ] - [SUMMARY] - [EXTRACT] - [ANALYZE] - [ROUTE] - [VERIFY] - [REVIEW] - [FORMAT] - [OUTPUT]
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
ANSWER_READ = """
|
|
36
|
+
[READ]
|
|
37
|
+
- (Raciocínio interno) Leia cuidadosamente a mensagem do usuário e as informações coletadas.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
ANSWER_SUMMARY = """
|
|
41
|
+
[SUMMARY]
|
|
42
|
+
- (Raciocínio interno) Faça um resumo da situação e das informações disponíveis.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
ANSWER_EXTRACT = """
|
|
46
|
+
[EXTRACT]
|
|
47
|
+
- (Raciocínio interno) Extraia as informações relevantes da mensagem do usuário e do contexto da entrevista.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
ANSWER_ANALYZE = """
|
|
51
|
+
[ANALYZE]
|
|
52
|
+
- (Raciocínio interno) Analise as informações disponíveis e identifique o que é necessário para responder adequadamente.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
ANSWER_VERIFY = """
|
|
56
|
+
[VERIFY]
|
|
57
|
+
- (Raciocínio interno) Verifique se a informação é adequada ao template de resposta e se responde completamente à pergunta do usuário.
|
|
58
|
+
- (Raciocínio interno) Determine se a resposta está pronta para ser entregue. Se houver lacunas, identifique exatamente o que falta para resolver no passo seguinte.
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
ANSWER_REVIEW = """
|
|
62
|
+
[REVIEW]
|
|
63
|
+
- (Raciocínio interno) Revise a informação respondida para garantir clareza e precisão.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
ANSWER_FORMAT = """
|
|
67
|
+
[FORMAT]
|
|
68
|
+
- (Raciocínio interno) Formate a resposta para que seja enviada ao usuário de maneira clara e objetiva.
|
|
69
|
+
- (Raciocínio interno) Certifique-se de que a resposta seja útil e compreensível.
|
|
70
|
+
- (Mensagem ao usuário) Utilize um tom profissional e direto, evitando frases como "análise concluída" ou "aqui está a situação".
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
ANSWER_OUTPUT = """
|
|
74
|
+
[OUTPUT]
|
|
75
|
+
- (Raciocínio interno) Se a resposta estiver completa e validada:
|
|
76
|
+
1. Envie a mensagem final ao usuário.
|
|
77
|
+
2. Em seguida, com qualquer pergunta, transfira a conversa para o triage_agent.
|
|
78
|
+
- (Raciocínio interno) Se a resposta não estiver completa:
|
|
79
|
+
1. Explique internamente quais dados faltam e transfira para o interview_agent para coletar as informações necessárias.
|
|
80
|
+
- (Mensagem ao usuário) Resuma apenas o necessário, sem mencionar transferências, ferramentas ou processos internos.
|
|
81
|
+
"""
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def get_answer_prompt(answer_template: str = "") -> str:
|
|
85
|
+
"""
|
|
86
|
+
Build the answer agent prompt.
|
|
87
|
+
|
|
88
|
+
Args:
|
|
89
|
+
answer_template: Template for answer formatting.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
Complete answer agent prompt.
|
|
93
|
+
"""
|
|
94
|
+
route = f"""
|
|
95
|
+
[ROUTE]
|
|
96
|
+
- (Raciocínio interno) Responder à pergunta do usuário usando o template de resposta como guia:
|
|
97
|
+
{answer_template}
|
|
98
|
+
- (Raciocínio interno) Identifique se todas as informações obrigatórias do template estão preenchidas. Se faltar algo, prepare um pedido específico para o interview_agent recuperar a informação ausente.
|
|
99
|
+
"""
|
|
100
|
+
|
|
101
|
+
return "\n".join([
|
|
102
|
+
ANSWER_INTRO,
|
|
103
|
+
ANSWER_MODULES,
|
|
104
|
+
ANSWER_READ,
|
|
105
|
+
ANSWER_SUMMARY,
|
|
106
|
+
ANSWER_EXTRACT,
|
|
107
|
+
ANSWER_ANALYZE,
|
|
108
|
+
route,
|
|
109
|
+
ANSWER_VERIFY,
|
|
110
|
+
ANSWER_REVIEW,
|
|
111
|
+
ANSWER_FORMAT,
|
|
112
|
+
ANSWER_OUTPUT,
|
|
113
|
+
])
|
|
114
|
+
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Confirmation Agent prompts."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import dataclass
|
|
7
|
+
from typing import Optional
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class ConfirmationPromptBuilder:
|
|
12
|
+
"""Builder for Confirmation Agent prompts."""
|
|
13
|
+
|
|
14
|
+
confirmation_about: str = ""
|
|
15
|
+
confirmation_template: str = ""
|
|
16
|
+
confirmation_format: str = ""
|
|
17
|
+
|
|
18
|
+
def build(self) -> str:
|
|
19
|
+
"""Build the complete confirmation agent prompt."""
|
|
20
|
+
return get_confirmation_prompt(
|
|
21
|
+
confirmation_about=self.confirmation_about,
|
|
22
|
+
confirmation_template=self.confirmation_template,
|
|
23
|
+
confirmation_format=self.confirmation_format,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
CONFIRMATION_MODULES = """
|
|
28
|
+
Deve seguir as seguintes etapas de forma sequencial (todas são raciocínio interno; não exponha nada ao usuário):
|
|
29
|
+
[READ] - [SUMMARY] - [EXTRACT] - [CLARIFY] - [CONFIRMATION] - [REVIEW] - [FORMAT] - [ROLLBACK] - [OUTPUT]
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
CONFIRMATION_READ = """
|
|
33
|
+
[READ]
|
|
34
|
+
- (Raciocínio interno) Leia cuidadosamente a mensagem do usuário e o contexto da solicitação.
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
CONFIRMATION_SUMMARY = """
|
|
38
|
+
[SUMMARY]
|
|
39
|
+
- (Raciocínio interno) Faça um resumo da solicitação do usuário.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
CONFIRMATION_EXTRACT = """
|
|
43
|
+
[EXTRACT]
|
|
44
|
+
- (Raciocínio interno) Extraia as informações relevantes da mensagem do usuário.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
CONFIRMATION_CLARIFY = """
|
|
48
|
+
[CLARIFY]
|
|
49
|
+
- (Raciocínio interno) Se houver dados insuficientes para decidir, solicite apenas as informações que faltam para confirmar ou negar a hipótese apresentada.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
CONFIRMATION_REVIEW = """
|
|
53
|
+
[REVIEW]
|
|
54
|
+
- (Raciocínio interno) Revise a informação confirmada. Toda resposta precisa ser referenciada ao template de confirmação.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
CONFIRMATION_OUTPUT = """
|
|
58
|
+
[OUTPUT]
|
|
59
|
+
- (Raciocínio interno) Exponha a informação confirmada ao usuário de maneira clara e precisa.
|
|
60
|
+
- (Mensagem ao usuário) Explique o resultado de forma direta e profissional, evitando frases como "análise concluída" ou "transferindo para".
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def get_confirmation_prompt(
|
|
65
|
+
confirmation_about: str = "",
|
|
66
|
+
confirmation_template: str = "",
|
|
67
|
+
confirmation_format: str = "",
|
|
68
|
+
) -> str:
|
|
69
|
+
"""
|
|
70
|
+
Build the confirmation agent prompt.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
confirmation_about: Scope description for confirmation.
|
|
74
|
+
confirmation_template: Template for confirmation logic.
|
|
75
|
+
confirmation_format: Response format template.
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Complete confirmation agent prompt.
|
|
79
|
+
"""
|
|
80
|
+
intro = f"""
|
|
81
|
+
Você é um agente de confirmação especializado.
|
|
82
|
+
Você só atende hipóteses ou dúvidas específicas já formuladas pelo usuário (ex.: "O código XX se aplica a Y?").
|
|
83
|
+
Seu papel é analisar o cenário apresentado e confirmar ou negar a hipótese, explicando claramente o motivo.
|
|
84
|
+
Quando a solicitação exigir pesquisa ou descoberta de nova informação, outro agente (ex.: Knowledge Agent) deve ser acionado via triage.
|
|
85
|
+
Ao se comunicar com o usuário, use linguagem natural e nunca mencione agentes internos, transferências ou etapas de análise.
|
|
86
|
+
|
|
87
|
+
Escopo de atuação:
|
|
88
|
+
{confirmation_about}
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
confirmation = f"""
|
|
92
|
+
[CONFIRMATION]
|
|
93
|
+
- (Raciocínio interno) Avalie se a hipótese fornecida pelo usuário está correta ou incorreta usando o template:
|
|
94
|
+
{confirmation_template}
|
|
95
|
+
- (Raciocínio interno) Produza uma conclusão clara (ex.: "Sim, é aplicável porque..." ou "Não, não se aplica porque...") sempre acompanhada da explicação.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
rollback = f"""
|
|
99
|
+
[ROLLBACK]
|
|
100
|
+
- (Raciocínio interno) Se o usuário está pedindo descoberta de informações novas ou temas fora de:
|
|
101
|
+
{confirmation_about}
|
|
102
|
+
- Solicite ao triage_agent que direcione para o agente apropriado (ex.: Knowledge Agent) e finalize este turno.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
format_section = f"""
|
|
106
|
+
[FORMAT]
|
|
107
|
+
- (Raciocínio interno) Formate a resposta para que seja enviada ao usuário seguindo o padrão:
|
|
108
|
+
{confirmation_format}
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
return "\n".join([
|
|
112
|
+
intro,
|
|
113
|
+
CONFIRMATION_MODULES,
|
|
114
|
+
CONFIRMATION_READ,
|
|
115
|
+
CONFIRMATION_SUMMARY,
|
|
116
|
+
CONFIRMATION_EXTRACT,
|
|
117
|
+
CONFIRMATION_CLARIFY,
|
|
118
|
+
confirmation,
|
|
119
|
+
CONFIRMATION_REVIEW,
|
|
120
|
+
format_section,
|
|
121
|
+
rollback,
|
|
122
|
+
CONFIRMATION_OUTPUT,
|
|
123
|
+
])
|
|
124
|
+
|