atendentepro 0.5.6__py3-none-any.whl → 0.5.7__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/__init__.py CHANGED
@@ -144,6 +144,14 @@ from atendentepro.utils import (
144
144
  get_async_client,
145
145
  get_provider,
146
146
  configure_tracing,
147
+ # MonkAI Trace
148
+ configure_monkai_trace,
149
+ get_monkai_hooks,
150
+ set_monkai_user,
151
+ set_monkai_input,
152
+ run_with_monkai_tracking,
153
+ # Application Insights
154
+ configure_application_insights,
147
155
  )
148
156
 
149
157
  __all__ = [
@@ -225,5 +233,13 @@ __all__ = [
225
233
  "get_async_client",
226
234
  "get_provider",
227
235
  "configure_tracing",
236
+ # MonkAI Trace
237
+ "configure_monkai_trace",
238
+ "get_monkai_hooks",
239
+ "set_monkai_user",
240
+ "set_monkai_input",
241
+ "run_with_monkai_tracking",
242
+ # Application Insights
243
+ "configure_application_insights",
228
244
  ]
229
245
 
@@ -7,13 +7,34 @@ from .openai_client import (
7
7
  AsyncClient,
8
8
  Provider,
9
9
  )
10
- from .tracing import configure_tracing
10
+ from .tracing import (
11
+ # MonkAI Trace (recommended)
12
+ configure_monkai_trace,
13
+ get_monkai_hooks,
14
+ set_monkai_user,
15
+ set_monkai_input,
16
+ run_with_monkai_tracking,
17
+ # Application Insights (Azure)
18
+ configure_application_insights,
19
+ # Legacy
20
+ configure_tracing,
21
+ )
11
22
 
12
23
  __all__ = [
24
+ # OpenAI Client
13
25
  "get_async_client",
14
26
  "get_provider",
15
27
  "AsyncClient",
16
28
  "Provider",
29
+ # MonkAI Trace
30
+ "configure_monkai_trace",
31
+ "get_monkai_hooks",
32
+ "set_monkai_user",
33
+ "set_monkai_input",
34
+ "run_with_monkai_tracking",
35
+ # Application Insights
36
+ "configure_application_insights",
37
+ # Legacy
17
38
  "configure_tracing",
18
39
  ]
19
40
 
@@ -2,20 +2,200 @@
2
2
  """
3
3
  Tracing configuration for AtendentePro.
4
4
 
5
- Provides optional Application Insights integration for telemetry.
5
+ Provides optional tracing integrations:
6
+ - MonkAI Trace (recommended): Full agent tracking with token segmentation
7
+ - Application Insights: Azure telemetry
8
+
9
+ MonkAI Trace: https://github.com/BeMonkAI/monkai-trace
6
10
  """
7
11
 
8
12
  from __future__ import annotations
9
13
 
10
14
  import logging
11
- from typing import Optional
15
+ import os
16
+ from typing import Optional, Any, TYPE_CHECKING
12
17
 
13
18
  from atendentepro.config import get_config
14
19
 
20
+ if TYPE_CHECKING:
21
+ from agents import Agent
22
+
15
23
  logger = logging.getLogger(__name__)
16
24
 
17
25
 
18
- def configure_tracing(connection_string: Optional[str] = None) -> bool:
26
+ # =============================================================================
27
+ # MONKAI TRACE INTEGRATION
28
+ # =============================================================================
29
+
30
+ _MONKAI_HOOKS: Optional[Any] = None
31
+
32
+
33
+ def configure_monkai_trace(
34
+ tracer_token: Optional[str] = None,
35
+ namespace: Optional[str] = None,
36
+ inactivity_timeout: int = 120,
37
+ batch_size: int = 1,
38
+ ) -> bool:
39
+ """
40
+ Configure MonkAI Trace for agent tracking.
41
+
42
+ MonkAI Trace provides comprehensive agent monitoring with:
43
+ - Automatic session management
44
+ - Token segmentation (input, output, process, memory)
45
+ - Multi-agent handoff tracking
46
+ - Web search and tool tracking
47
+
48
+ Args:
49
+ tracer_token: MonkAI tracer token (or env MONKAI_TRACER_TOKEN)
50
+ namespace: Namespace for grouping traces (default: "atendentepro")
51
+ inactivity_timeout: Session timeout in seconds (default: 120)
52
+ batch_size: Upload batch size, 1 for real-time (default: 1)
53
+
54
+ Returns:
55
+ True if MonkAI Trace was configured, False otherwise.
56
+
57
+ Example:
58
+ >>> from atendentepro.utils import configure_monkai_trace
59
+ >>> configure_monkai_trace(tracer_token="tk_your_token")
60
+ True
61
+
62
+ >>> # Or via environment variable
63
+ >>> # export MONKAI_TRACER_TOKEN="tk_your_token"
64
+ >>> configure_monkai_trace()
65
+ True
66
+ """
67
+ global _MONKAI_HOOKS
68
+
69
+ # Get token from parameter or environment
70
+ token = tracer_token or os.environ.get("MONKAI_TRACER_TOKEN")
71
+
72
+ if not token:
73
+ logger.debug("No MonkAI tracer token provided. MonkAI Trace disabled.")
74
+ return False
75
+
76
+ try:
77
+ from monkai_trace.integrations.openai_agents import MonkAIRunHooks
78
+
79
+ _MONKAI_HOOKS = MonkAIRunHooks(
80
+ tracer_token=token,
81
+ namespace=namespace or "atendentepro",
82
+ inactivity_timeout=inactivity_timeout,
83
+ batch_size=batch_size,
84
+ )
85
+
86
+ logger.info(f"MonkAI Trace configured successfully (namespace: {namespace or 'atendentepro'})")
87
+ return True
88
+
89
+ except ImportError:
90
+ logger.warning(
91
+ "MonkAI Trace not available. "
92
+ "Install 'monkai-trace' for agent tracking: pip install monkai-trace"
93
+ )
94
+ return False
95
+ except Exception as e:
96
+ logger.error(f"Failed to configure MonkAI Trace: {e}")
97
+ return False
98
+
99
+
100
+ def get_monkai_hooks() -> Optional[Any]:
101
+ """
102
+ Get the configured MonkAI Run Hooks.
103
+
104
+ Returns:
105
+ MonkAIRunHooks instance if configured, None otherwise.
106
+
107
+ Example:
108
+ >>> hooks = get_monkai_hooks()
109
+ >>> if hooks:
110
+ ... result = await Runner.run(agent, messages, hooks=hooks)
111
+ """
112
+ return _MONKAI_HOOKS
113
+
114
+
115
+ def set_monkai_user(user_id: str) -> None:
116
+ """
117
+ Set the user ID for MonkAI session tracking.
118
+
119
+ Useful for multi-user scenarios like WhatsApp bots.
120
+
121
+ Args:
122
+ user_id: Unique user identifier (phone, email, etc.)
123
+
124
+ Example:
125
+ >>> set_monkai_user("5511999999999") # WhatsApp
126
+ >>> set_monkai_user("user@email.com") # Email
127
+ """
128
+ if _MONKAI_HOOKS:
129
+ _MONKAI_HOOKS.set_user_id(user_id)
130
+
131
+
132
+ def set_monkai_input(user_input: str) -> None:
133
+ """
134
+ Set the user input for MonkAI tracking.
135
+
136
+ Call this before running the agent to capture the user message.
137
+
138
+ Args:
139
+ user_input: The user's message/query
140
+
141
+ Example:
142
+ >>> set_monkai_input("Como faço para cancelar minha assinatura?")
143
+ >>> result = await Runner.run(agent, messages, hooks=get_monkai_hooks())
144
+ """
145
+ if _MONKAI_HOOKS:
146
+ _MONKAI_HOOKS.set_user_input(user_input)
147
+
148
+
149
+ async def run_with_monkai_tracking(
150
+ agent: "Agent",
151
+ user_input: str,
152
+ user_id: Optional[str] = None,
153
+ ) -> Any:
154
+ """
155
+ Run an agent with MonkAI tracking enabled.
156
+
157
+ This is the recommended way to run agents with full tracking.
158
+ Captures internal tools (web_search, file_search) automatically.
159
+
160
+ Args:
161
+ agent: The agent to run
162
+ user_input: User's message/query
163
+ user_id: Optional user identifier for session management
164
+
165
+ Returns:
166
+ RunResult from the agent execution
167
+
168
+ Example:
169
+ >>> from atendentepro.utils import configure_monkai_trace, run_with_monkai_tracking
170
+ >>> configure_monkai_trace(tracer_token="tk_your_token")
171
+ >>> result = await run_with_monkai_tracking(network.triage, "Olá!")
172
+ """
173
+ if not _MONKAI_HOOKS:
174
+ # Fallback to normal execution without tracking
175
+ from agents import Runner
176
+ return await Runner.run(agent, user_input)
177
+
178
+ try:
179
+ from monkai_trace.integrations.openai_agents import MonkAIRunHooks
180
+
181
+ if user_id:
182
+ _MONKAI_HOOKS.set_user_id(user_id)
183
+
184
+ # Use run_with_tracking for full internal tools capture
185
+ return await MonkAIRunHooks.run_with_tracking(agent, user_input, _MONKAI_HOOKS)
186
+
187
+ except Exception as e:
188
+ logger.error(f"Error running with MonkAI tracking: {e}")
189
+ # Fallback to normal execution
190
+ from agents import Runner
191
+ return await Runner.run(agent, user_input)
192
+
193
+
194
+ # =============================================================================
195
+ # APPLICATION INSIGHTS INTEGRATION (Azure)
196
+ # =============================================================================
197
+
198
+ def configure_application_insights(connection_string: Optional[str] = None) -> bool:
19
199
  """
20
200
  Configure Application Insights tracing if connection string is available.
21
201
 
@@ -69,3 +249,15 @@ def configure_tracing(connection_string: Optional[str] = None) -> bool:
69
249
  logger.error(f"Failed to configure tracing: {e}")
70
250
  return False
71
251
 
252
+
253
+ # =============================================================================
254
+ # LEGACY ALIAS
255
+ # =============================================================================
256
+
257
+ def configure_tracing(connection_string: Optional[str] = None) -> bool:
258
+ """
259
+ Legacy alias for configure_application_insights.
260
+
261
+ Deprecated: Use configure_monkai_trace() or configure_application_insights().
262
+ """
263
+ return configure_application_insights(connection_string)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: atendentepro
3
- Version: 0.5.6
3
+ Version: 0.5.7
4
4
  Summary: Sistema de Atendimento Inteligente com Múltiplos Agentes IA - Biblioteca independente e modular baseada no OpenAI Agents SDK
5
5
  Author-email: BeMonkAI <contato@monkai.com.br>
6
6
  Maintainer-email: BeMonkAI <contato@monkai.com.br>
@@ -79,6 +79,7 @@ Uma biblioteca Python modular para criar sistemas de atendimento automatizado us
79
79
  - [Escalation Agent](#-escalation-agent)
80
80
  - [Feedback Agent](#-feedback-agent)
81
81
  - [Fluxo de Handoffs](#-fluxo-de-handoffs)
82
+ - [Tracing e Monitoramento](#-tracing-e-monitoramento)
82
83
  - [Suporte](#-suporte)
83
84
 
84
85
  ---
@@ -609,6 +610,83 @@ network = create_standard_network(
609
610
 
610
611
  ---
611
612
 
613
+ ## 📊 Tracing e Monitoramento
614
+
615
+ ### MonkAI Trace (Recomendado)
616
+
617
+ Integração com [MonkAI Trace](https://github.com/BeMonkAI/monkai-trace) para monitoramento completo de agentes:
618
+
619
+ ```bash
620
+ pip install monkai-trace
621
+ ```
622
+
623
+ ```python
624
+ from atendentepro import (
625
+ activate,
626
+ create_standard_network,
627
+ configure_monkai_trace,
628
+ run_with_monkai_tracking,
629
+ )
630
+
631
+ # 1. Ativar biblioteca
632
+ activate("ATP_seu-token")
633
+
634
+ # 2. Configurar MonkAI Trace
635
+ configure_monkai_trace(
636
+ tracer_token="tk_seu_token_monkai", # ou env MONKAI_TRACER_TOKEN
637
+ namespace="meu-projeto",
638
+ )
639
+
640
+ # 3. Criar rede
641
+ network = create_standard_network(...)
642
+
643
+ # 4. Executar com tracking
644
+ result = await run_with_monkai_tracking(
645
+ agent=network.triage,
646
+ user_input="Olá, preciso de ajuda",
647
+ user_id="user123", # Opcional: para sessões multi-usuário
648
+ )
649
+ ```
650
+
651
+ **Recursos do MonkAI Trace:**
652
+ - ✅ Tracking automático de sessões
653
+ - ✅ Segmentação de tokens (input, output, process, memory)
654
+ - ✅ Rastreamento de handoffs entre agentes
655
+ - ✅ Captura de ferramentas internas (web_search, RAG)
656
+ - ✅ Suporte multi-usuário (WhatsApp, chat)
657
+
658
+ ### Uso Avançado
659
+
660
+ ```python
661
+ from atendentepro import (
662
+ get_monkai_hooks,
663
+ set_monkai_user,
664
+ set_monkai_input,
665
+ )
666
+ from agents import Runner
667
+
668
+ # Para controle manual
669
+ hooks = get_monkai_hooks()
670
+ set_monkai_user("5511999999999") # WhatsApp
671
+ set_monkai_input("Como cancelar?")
672
+
673
+ result = await Runner.run(network.triage, messages, hooks=hooks)
674
+ ```
675
+
676
+ ### Application Insights (Azure)
677
+
678
+ Para Azure, use Application Insights:
679
+
680
+ ```python
681
+ from atendentepro import configure_application_insights
682
+
683
+ configure_application_insights(
684
+ connection_string="InstrumentationKey=..."
685
+ )
686
+ ```
687
+
688
+ ---
689
+
612
690
  ## 🤝 Suporte
613
691
 
614
692
  - 📧 **Email:** contato@monkai.com.br
@@ -1,5 +1,5 @@
1
1
  atendentepro/README.md,sha256=AMVMJlVOlXcwU_kRGBiIoSn8hASLHrhZwxV1jr1LJsU,43012
2
- atendentepro/__init__.py,sha256=r_9RwvfKcvcS6bk2a1sdQsQyf_CUW-tljE-vh3TeLyw,5150
2
+ atendentepro/__init__.py,sha256=A7ANs1G18HZEhl-C_OVVdOzM0KCRDo-sX1Veq4IYwDo,5572
3
3
  atendentepro/license.py,sha256=rlPtysXNqAzEQkP2VjUAVu_nMndhPgfKv1yN2ruUYVI,17570
4
4
  atendentepro/network.py,sha256=s7h9if2oS_15BL8VoONjMlihEFCkJqdHxR5WFL81gl4,17310
5
5
  atendentepro/agents/__init__.py,sha256=OcPhG1Dp6xe49B5YIti4HVmaZDoDIrFLfRa8GmI4jpQ,1638
@@ -32,12 +32,12 @@ atendentepro/prompts/onboarding.py,sha256=78fSIh2ifsGeoav8DV41_jnyU157c0dtggJujc
32
32
  atendentepro/prompts/triage.py,sha256=bSdEVheGy03r5P6MQuv7NwhN2_wrt0mK80F9f_LskRU,1283
33
33
  atendentepro/templates/__init__.py,sha256=kSXiDXVIZKKsSn2GuHBcHsnXqVRcNWyBzRlKl9HYoCI,1137
34
34
  atendentepro/templates/manager.py,sha256=KdE4khWDMD2S607TDTMkvJ8lZzQ9D_TD_lBaXYSTBzI,17932
35
- atendentepro/utils/__init__.py,sha256=6EgS4DrW4fG17JdaHNKWMpzicigfFLVJO2VxPV73k9c,334
35
+ atendentepro/utils/__init__.py,sha256=WCJ6_btsLaI6xxHXvNHNue-nKrXWTKscNZGTToQiJ8A,833
36
36
  atendentepro/utils/openai_client.py,sha256=R0ns7SU36vTgploq14-QJMTke1pPxcAXlENDeoHU0L4,4552
37
- atendentepro/utils/tracing.py,sha256=HQ3l4IiNcesCJ6l5qcERWyeBQav0G1ea-H8Rei6eQpE,2319
38
- atendentepro-0.5.6.dist-info/licenses/LICENSE,sha256=TF6CdXxePoT9DXtPnCejiU5mUwWzrFzd1iyWJyoMauA,983
39
- atendentepro-0.5.6.dist-info/METADATA,sha256=ujtXRzOUoraqgh2a4hX9qP7pTKEXNS5S5QoZ0Kj64v0,19013
40
- atendentepro-0.5.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
- atendentepro-0.5.6.dist-info/entry_points.txt,sha256=OP0upzqJF3MLS6VX-M-5BfUwx5YLJO2sJ3YBAp4e6yI,89
42
- atendentepro-0.5.6.dist-info/top_level.txt,sha256=BFasD4SMmgDUmWKlTIZ1PeuukoRBhyiMIz8umKWVCcs,13
43
- atendentepro-0.5.6.dist-info/RECORD,,
37
+ atendentepro/utils/tracing.py,sha256=kpTPw1PF4rR1qq1RyBnAaPIQIJRka4RF8MfG_JrRJ7U,8486
38
+ atendentepro-0.5.7.dist-info/licenses/LICENSE,sha256=TF6CdXxePoT9DXtPnCejiU5mUwWzrFzd1iyWJyoMauA,983
39
+ atendentepro-0.5.7.dist-info/METADATA,sha256=sNb7PC8RcGrtRtciak-J_yiJedDxquF7N2mtl_4QwFo,20757
40
+ atendentepro-0.5.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
41
+ atendentepro-0.5.7.dist-info/entry_points.txt,sha256=OP0upzqJF3MLS6VX-M-5BfUwx5YLJO2sJ3YBAp4e6yI,89
42
+ atendentepro-0.5.7.dist-info/top_level.txt,sha256=BFasD4SMmgDUmWKlTIZ1PeuukoRBhyiMIz8umKWVCcs,13
43
+ atendentepro-0.5.7.dist-info/RECORD,,