hanzo-agent 0.0.4__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.
Files changed (80) hide show
  1. agents/__init__.py +332 -0
  2. agents/_config.py +26 -0
  3. agents/_debug.py +19 -0
  4. agents/_run_impl.py +825 -0
  5. agents/_utils.py +63 -0
  6. agents/agent.py +173 -0
  7. agents/agent_output.py +146 -0
  8. agents/computer.py +107 -0
  9. agents/exceptions.py +63 -0
  10. agents/extensions/__init__.py +12 -0
  11. agents/extensions/cli/__init__.py +11 -0
  12. agents/extensions/cli/cli_agent.py +255 -0
  13. agents/extensions/handoff_filters.py +71 -0
  14. agents/extensions/handoff_prompt.py +19 -0
  15. agents/extensions/marketplace/__init__.py +24 -0
  16. agents/extensions/marketplace/marketplace.py +418 -0
  17. agents/extensions/tee/__init__.py +26 -0
  18. agents/extensions/tee/tee.py +429 -0
  19. agents/extensions/web3/__init__.py +27 -0
  20. agents/extensions/web3/wallet.py +389 -0
  21. agents/extensions/web3/web3_agent.py +383 -0
  22. agents/extensions/web3/web3_network.py +447 -0
  23. agents/function_schema.py +347 -0
  24. agents/guardrail.py +342 -0
  25. agents/handoffs.py +242 -0
  26. agents/items.py +249 -0
  27. agents/lifecycle.py +107 -0
  28. agents/logger.py +3 -0
  29. agents/memory/__init__.py +28 -0
  30. agents/memory/memory.py +349 -0
  31. agents/memory/retriever.py +205 -0
  32. agents/memory/store.py +458 -0
  33. agents/memory/types.py +70 -0
  34. agents/model_settings.py +57 -0
  35. agents/models/__init__.py +0 -0
  36. agents/models/_openai_shared.py +34 -0
  37. agents/models/fake_id.py +5 -0
  38. agents/models/hanzo_node_provider.py +104 -0
  39. agents/models/interface.py +107 -0
  40. agents/models/openai_chatcompletions.py +1063 -0
  41. agents/models/openai_provider.py +97 -0
  42. agents/models/openai_responses.py +411 -0
  43. agents/network/__init__.py +32 -0
  44. agents/network/network.py +437 -0
  45. agents/network/node.py +77 -0
  46. agents/network/router.py +408 -0
  47. agents/orchestration/__init__.py +24 -0
  48. agents/orchestration/executor.py +492 -0
  49. agents/orchestration/orchestrator.py +335 -0
  50. agents/orchestration/ui_stream.py +377 -0
  51. agents/orchestration/workflow.py +512 -0
  52. agents/reflexion.py +78 -0
  53. agents/result.py +224 -0
  54. agents/run.py +931 -0
  55. agents/run_context.py +26 -0
  56. agents/state/__init__.py +20 -0
  57. agents/state/namespace.py +62 -0
  58. agents/state/serializer.py +60 -0
  59. agents/state/store.py +346 -0
  60. agents/stream_events.py +60 -0
  61. agents/strict_schema.py +184 -0
  62. agents/tool.py +290 -0
  63. agents/tool_enhanced.py +392 -0
  64. agents/tracing/__init__.py +97 -0
  65. agents/tracing/create.py +312 -0
  66. agents/tracing/logger.py +3 -0
  67. agents/tracing/processor_interface.py +69 -0
  68. agents/tracing/processors.py +267 -0
  69. agents/tracing/scope.py +49 -0
  70. agents/tracing/setup.py +215 -0
  71. agents/tracing/span_data.py +188 -0
  72. agents/tracing/spans.py +264 -0
  73. agents/tracing/traces.py +195 -0
  74. agents/tracing/util.py +17 -0
  75. agents/usage.py +22 -0
  76. agents/version.py +7 -0
  77. hanzo_agent-0.0.4.dist-info/METADATA +380 -0
  78. hanzo_agent-0.0.4.dist-info/RECORD +80 -0
  79. hanzo_agent-0.0.4.dist-info/WHEEL +4 -0
  80. hanzo_agent-0.0.4.dist-info/licenses/LICENSE +21 -0
agents/__init__.py ADDED
@@ -0,0 +1,332 @@
1
+ import logging
2
+ import sys
3
+ from typing import Literal
4
+
5
+ from openai import AsyncOpenAI
6
+ import hanzo_async
7
+
8
+ # Configure unified event loop (uvloop)
9
+ hanzo_async.configure_loop()
10
+
11
+ from . import _config
12
+ from .agent import Agent
13
+ from .agent_output import AgentOutputSchema
14
+ from .computer import AsyncComputer, Button, Computer, Environment
15
+ from .exceptions import (
16
+ AgentsException,
17
+ InputGuardrailTripwireTriggered,
18
+ MaxTurnsExceeded,
19
+ ModelBehaviorError,
20
+ OutputGuardrailTripwireTriggered,
21
+ UserError,
22
+ )
23
+ from .guardrail import (
24
+ GuardrailFunctionOutput,
25
+ InputGuardrail,
26
+ InputGuardrailResult,
27
+ OutputGuardrail,
28
+ OutputGuardrailResult,
29
+ input_guardrail,
30
+ output_guardrail,
31
+ )
32
+ from .handoffs import Handoff, HandoffInputData, HandoffInputFilter, handoff
33
+ from .items import (
34
+ HandoffCallItem,
35
+ HandoffOutputItem,
36
+ ItemHelpers,
37
+ MessageOutputItem,
38
+ ModelResponse,
39
+ ReasoningItem,
40
+ RunItem,
41
+ ToolCallItem,
42
+ ToolCallOutputItem,
43
+ TResponseInputItem,
44
+ )
45
+ from .lifecycle import AgentHooks, RunHooks
46
+ from .model_settings import ModelSettings
47
+ from .models.interface import Model, ModelProvider, ModelTracing
48
+ from .models.openai_chatcompletions import OpenAIChatCompletionsModel
49
+ from .models.openai_provider import OpenAIProvider
50
+ from .models.openai_responses import OpenAIResponsesModel
51
+ from .models.hanzo_node_provider import HanzoNodeProvider, create_hanzo_node_provider
52
+ from .result import RunResult, RunResultStreaming
53
+ from .run import RunConfig, Runner
54
+ from .run_context import RunContextWrapper, TContext
55
+ from .stream_events import (
56
+ AgentUpdatedStreamEvent,
57
+ RawResponsesStreamEvent,
58
+ RunItemStreamEvent,
59
+ StreamEvent,
60
+ )
61
+ from .tool import (
62
+ ComputerTool,
63
+ FileSearchTool,
64
+ FunctionTool,
65
+ Tool,
66
+ WebSearchTool,
67
+ default_tool_error_function,
68
+ function_tool,
69
+ )
70
+ from .tracing import (
71
+ AgentSpanData,
72
+ CustomSpanData,
73
+ FunctionSpanData,
74
+ GenerationSpanData,
75
+ GuardrailSpanData,
76
+ HandoffSpanData,
77
+ Span,
78
+ SpanData,
79
+ SpanError,
80
+ Trace,
81
+ add_trace_processor,
82
+ agent_span,
83
+ custom_span,
84
+ function_span,
85
+ gen_span_id,
86
+ gen_trace_id,
87
+ generation_span,
88
+ get_current_span,
89
+ get_current_trace,
90
+ guardrail_span,
91
+ handoff_span,
92
+ set_trace_processors,
93
+ set_tracing_disabled,
94
+ set_tracing_export_api_key,
95
+ trace,
96
+ )
97
+ from .usage import Usage
98
+
99
+ # Network and orchestration imports
100
+ from .network import (
101
+ AgentNetwork,
102
+ NetworkConfig,
103
+ Router,
104
+ RoutingDecision,
105
+ RoutingStrategy,
106
+ SemanticRouter,
107
+ RuleBasedRouter,
108
+ LoadBalancingRouter,
109
+ routing_strategy,
110
+ NetworkNode,
111
+ NodeStatus,
112
+ )
113
+ from .state import (
114
+ StateStore,
115
+ InMemoryStateStore,
116
+ RedisStateStore,
117
+ FileStateStore,
118
+ StateNamespace,
119
+ StateSerializer,
120
+ JSONSerializer,
121
+ PickleSerializer,
122
+ )
123
+ from .memory import (
124
+ Memory,
125
+ MemoryEntry,
126
+ MemoryType,
127
+ MemoryStore,
128
+ InMemoryMemoryStore,
129
+ VectorMemoryStore,
130
+ MemoryRetriever,
131
+ SemanticRetriever,
132
+ RecencyRetriever,
133
+ HybridRetriever,
134
+ )
135
+ from .orchestration import (
136
+ Orchestrator,
137
+ OrchestrationConfig,
138
+ Workflow,
139
+ WorkflowStep,
140
+ StepType,
141
+ WorkflowExecutor,
142
+ ExecutionResult,
143
+ UIStreamer,
144
+ StreamUpdate,
145
+ UpdateType,
146
+ )
147
+ from .reflexion import ReflexionEngine, Rule
148
+
149
+
150
+ def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
151
+ """Set the default OpenAI API key to use for LLM requests (and optionally tracing(). This is
152
+ only necessary if the OPENAI_API_KEY environment variable is not already set.
153
+
154
+ If provided, this key will be used instead of the OPENAI_API_KEY environment variable.
155
+
156
+ Args:
157
+ key: The OpenAI key to use.
158
+ use_for_tracing: Whether to also use this key to send traces to OpenAI. Defaults to True
159
+ If False, you'll either need to set the OPENAI_API_KEY environment variable or call
160
+ set_tracing_export_api_key() with the API key you want to use for tracing.
161
+ """
162
+ _config.set_default_openai_key(key, use_for_tracing)
163
+
164
+
165
+ def set_default_openai_client(
166
+ client: AsyncOpenAI, use_for_tracing: bool = True
167
+ ) -> None:
168
+ """Set the default OpenAI client to use for LLM requests and/or tracing. If provided, this
169
+ client will be used instead of the default OpenAI client.
170
+
171
+ Args:
172
+ client: The OpenAI client to use.
173
+ use_for_tracing: Whether to use the API key from this client for uploading traces. If False,
174
+ you'll either need to set the OPENAI_API_KEY environment variable or call
175
+ set_tracing_export_api_key() with the API key you want to use for tracing.
176
+ """
177
+ _config.set_default_openai_client(client, use_for_tracing)
178
+
179
+
180
+ def set_default_openai_api(api: Literal["chat_completions", "responses"]) -> None:
181
+ """Set the default API to use for OpenAI LLM requests. By default, we will use the responses API
182
+ but you can set this to use the chat completions API instead.
183
+ """
184
+ _config.set_default_openai_api(api)
185
+
186
+
187
+ def enable_verbose_stdout_logging():
188
+ """Enables verbose logging to stdout. This is useful for debugging."""
189
+ logger = logging.getLogger("openai.agents")
190
+ logger.setLevel(logging.DEBUG)
191
+ logger.addHandler(logging.StreamHandler(sys.stdout))
192
+
193
+
194
+ __all__ = [
195
+ "Agent",
196
+ "Runner",
197
+ "Model",
198
+ "ModelProvider",
199
+ "ModelTracing",
200
+ "ModelSettings",
201
+ "OpenAIChatCompletionsModel",
202
+ "OpenAIProvider",
203
+ "OpenAIResponsesModel",
204
+ "HanzoNodeProvider",
205
+ "create_hanzo_node_provider",
206
+ "AgentOutputSchema",
207
+ "Computer",
208
+ "AsyncComputer",
209
+ "Environment",
210
+ "Button",
211
+ "AgentsException",
212
+ "InputGuardrailTripwireTriggered",
213
+ "OutputGuardrailTripwireTriggered",
214
+ "MaxTurnsExceeded",
215
+ "ModelBehaviorError",
216
+ "UserError",
217
+ "InputGuardrail",
218
+ "InputGuardrailResult",
219
+ "OutputGuardrail",
220
+ "OutputGuardrailResult",
221
+ "GuardrailFunctionOutput",
222
+ "input_guardrail",
223
+ "output_guardrail",
224
+ "handoff",
225
+ "Handoff",
226
+ "HandoffInputData",
227
+ "HandoffInputFilter",
228
+ "TResponseInputItem",
229
+ "MessageOutputItem",
230
+ "ModelResponse",
231
+ "RunItem",
232
+ "HandoffCallItem",
233
+ "HandoffOutputItem",
234
+ "ToolCallItem",
235
+ "ToolCallOutputItem",
236
+ "ReasoningItem",
237
+ "ModelResponse",
238
+ "ItemHelpers",
239
+ "RunHooks",
240
+ "AgentHooks",
241
+ "RunContextWrapper",
242
+ "TContext",
243
+ "RunResult",
244
+ "RunResultStreaming",
245
+ "RunConfig",
246
+ "RawResponsesStreamEvent",
247
+ "RunItemStreamEvent",
248
+ "AgentUpdatedStreamEvent",
249
+ "StreamEvent",
250
+ "FunctionTool",
251
+ "ComputerTool",
252
+ "FileSearchTool",
253
+ "Tool",
254
+ "WebSearchTool",
255
+ "function_tool",
256
+ "Usage",
257
+ "add_trace_processor",
258
+ "agent_span",
259
+ "custom_span",
260
+ "function_span",
261
+ "generation_span",
262
+ "get_current_span",
263
+ "get_current_trace",
264
+ "guardrail_span",
265
+ "handoff_span",
266
+ "set_trace_processors",
267
+ "set_tracing_disabled",
268
+ "trace",
269
+ "Trace",
270
+ "SpanError",
271
+ "Span",
272
+ "SpanData",
273
+ "AgentSpanData",
274
+ "CustomSpanData",
275
+ "FunctionSpanData",
276
+ "GenerationSpanData",
277
+ "GuardrailSpanData",
278
+ "HandoffSpanData",
279
+ "set_default_openai_key",
280
+ "set_default_openai_client",
281
+ "set_default_openai_api",
282
+ "set_tracing_export_api_key",
283
+ "enable_verbose_stdout_logging",
284
+ "gen_trace_id",
285
+ "gen_span_id",
286
+ "default_tool_error_function",
287
+ # Network exports
288
+ "AgentNetwork",
289
+ "NetworkConfig",
290
+ "Router",
291
+ "RoutingDecision",
292
+ "RoutingStrategy",
293
+ "SemanticRouter",
294
+ "RuleBasedRouter",
295
+ "LoadBalancingRouter",
296
+ "routing_strategy",
297
+ "NetworkNode",
298
+ "NodeStatus",
299
+ # State exports
300
+ "StateStore",
301
+ "InMemoryStateStore",
302
+ "RedisStateStore",
303
+ "FileStateStore",
304
+ "StateNamespace",
305
+ "StateSerializer",
306
+ "JSONSerializer",
307
+ "PickleSerializer",
308
+ # Memory exports
309
+ "Memory",
310
+ "MemoryEntry",
311
+ "MemoryType",
312
+ "MemoryStore",
313
+ "InMemoryMemoryStore",
314
+ "VectorMemoryStore",
315
+ "MemoryRetriever",
316
+ "SemanticRetriever",
317
+ "RecencyRetriever",
318
+ "HybridRetriever",
319
+ # Orchestration exports
320
+ "Orchestrator",
321
+ "OrchestrationConfig",
322
+ "Workflow",
323
+ "WorkflowStep",
324
+ "StepType",
325
+ "WorkflowExecutor",
326
+ "ExecutionResult",
327
+ "UIStreamer",
328
+ "StreamUpdate",
329
+ "UpdateType",
330
+ "ReflexionEngine",
331
+ "Rule",
332
+ ]
agents/_config.py ADDED
@@ -0,0 +1,26 @@
1
+ from openai import AsyncOpenAI
2
+ from typing_extensions import Literal
3
+
4
+ from .models import _openai_shared
5
+ from .tracing import set_tracing_export_api_key
6
+
7
+
8
+ def set_default_openai_key(key: str, use_for_tracing: bool) -> None:
9
+ _openai_shared.set_default_openai_key(key)
10
+
11
+ if use_for_tracing:
12
+ set_tracing_export_api_key(key)
13
+
14
+
15
+ def set_default_openai_client(client: AsyncOpenAI, use_for_tracing: bool) -> None:
16
+ _openai_shared.set_default_openai_client(client)
17
+
18
+ if use_for_tracing:
19
+ set_tracing_export_api_key(client.api_key)
20
+
21
+
22
+ def set_default_openai_api(api: Literal["chat_completions", "responses"]) -> None:
23
+ if api == "chat_completions":
24
+ _openai_shared.set_use_responses_by_default(False)
25
+ else:
26
+ _openai_shared.set_use_responses_by_default(True)
agents/_debug.py ADDED
@@ -0,0 +1,19 @@
1
+ import os
2
+
3
+
4
+ def _debug_flag_enabled(flag: str) -> bool:
5
+ flag_value = os.getenv(flag)
6
+ return flag_value is not None and (
7
+ flag_value == "1" or flag_value.lower() == "true"
8
+ )
9
+
10
+
11
+ DONT_LOG_MODEL_DATA = _debug_flag_enabled("OPENAI_AGENTS_DONT_LOG_MODEL_DATA")
12
+ """By default we don't log LLM inputs/outputs, to prevent exposing sensitive information. Set this
13
+ flag to enable logging them.
14
+ """
15
+
16
+ DONT_LOG_TOOL_DATA = _debug_flag_enabled("OPENAI_AGENTS_DONT_LOG_TOOL_DATA")
17
+ """By default we don't log tool call inputs/outputs, to prevent exposing sensitive information. Set
18
+ this flag to enable logging them.
19
+ """