forked from openai/openai-agents-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
230 lines (215 loc) · 6.11 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import logging
import sys
from typing import Literal
from openai import AsyncOpenAI
from . import _config
from .agent import Agent
from .agent_output import AgentOutputSchema
from .computer import AsyncComputer, Button, Computer, Environment
from .exceptions import (
AgentsException,
InputGuardrailTripwireTriggered,
MaxTurnsExceeded,
ModelBehaviorError,
OutputGuardrailTripwireTriggered,
UserError,
)
from .guardrail import (
GuardrailFunctionOutput,
InputGuardrail,
InputGuardrailResult,
OutputGuardrail,
OutputGuardrailResult,
input_guardrail,
output_guardrail,
)
from .handoffs import Handoff, HandoffInputData, HandoffInputFilter, handoff
from .items import (
HandoffCallItem,
HandoffOutputItem,
ItemHelpers,
MessageOutputItem,
ModelResponse,
ReasoningItem,
RunItem,
ToolCallItem,
ToolCallOutputItem,
TResponseInputItem,
)
from .lifecycle import AgentHooks, RunHooks
from .model_settings import ModelSettings
from .models.interface import Model, ModelProvider, ModelTracing
from .models.openai_chatcompletions import OpenAIChatCompletionsModel
from .models.openai_provider import OpenAIProvider
from .models.openai_responses import OpenAIResponsesModel
from .result import RunResult, RunResultStreaming
from .run import RunConfig, Runner
from .run_context import RunContextWrapper, TContext
from .stream_events import (
AgentUpdatedStreamEvent,
RawResponsesStreamEvent,
RunItemStreamEvent,
StreamEvent,
)
from .tool import (
ComputerTool,
FileSearchTool,
FunctionTool,
Tool,
WebSearchTool,
default_tool_error_function,
function_tool,
)
from .tracing import (
AgentSpanData,
CustomSpanData,
FunctionSpanData,
GenerationSpanData,
GuardrailSpanData,
HandoffSpanData,
Span,
SpanData,
SpanError,
Trace,
TracingProcessor,
add_trace_processor,
agent_span,
custom_span,
function_span,
gen_span_id,
gen_trace_id,
generation_span,
get_current_span,
get_current_trace,
guardrail_span,
handoff_span,
set_trace_processors,
set_tracing_disabled,
set_tracing_export_api_key,
trace,
)
from .usage import Usage
def set_default_openai_key(key: str, use_for_tracing: bool = True) -> None:
"""Set the default OpenAI API key to use for LLM requests (and optionally tracing(). This is
only necessary if the OPENAI_API_KEY environment variable is not already set.
If provided, this key will be used instead of the OPENAI_API_KEY environment variable.
Args:
key: The OpenAI key to use.
use_for_tracing: Whether to also use this key to send traces to OpenAI. Defaults to True
If False, you'll either need to set the OPENAI_API_KEY environment variable or call
set_tracing_export_api_key() with the API key you want to use for tracing.
"""
_config.set_default_openai_key(key, use_for_tracing)
def set_default_openai_client(client: AsyncOpenAI, use_for_tracing: bool = True) -> None:
"""Set the default OpenAI client to use for LLM requests and/or tracing. If provided, this
client will be used instead of the default OpenAI client.
Args:
client: The OpenAI client to use.
use_for_tracing: Whether to use the API key from this client for uploading traces. If False,
you'll either need to set the OPENAI_API_KEY environment variable or call
set_tracing_export_api_key() with the API key you want to use for tracing.
"""
_config.set_default_openai_client(client, use_for_tracing)
def set_default_openai_api(api: Literal["chat_completions", "responses"]) -> None:
"""Set the default API to use for OpenAI LLM requests. By default, we will use the responses API
but you can set this to use the chat completions API instead.
"""
_config.set_default_openai_api(api)
def enable_verbose_stdout_logging():
"""Enables verbose logging to stdout. This is useful for debugging."""
logger = logging.getLogger("openai.agents")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler(sys.stdout))
__all__ = [
"Agent",
"Runner",
"Model",
"ModelProvider",
"ModelTracing",
"ModelSettings",
"OpenAIChatCompletionsModel",
"OpenAIProvider",
"OpenAIResponsesModel",
"AgentOutputSchema",
"Computer",
"AsyncComputer",
"Environment",
"Button",
"AgentsException",
"InputGuardrailTripwireTriggered",
"OutputGuardrailTripwireTriggered",
"MaxTurnsExceeded",
"ModelBehaviorError",
"UserError",
"InputGuardrail",
"InputGuardrailResult",
"OutputGuardrail",
"OutputGuardrailResult",
"GuardrailFunctionOutput",
"input_guardrail",
"output_guardrail",
"handoff",
"Handoff",
"HandoffInputData",
"HandoffInputFilter",
"TResponseInputItem",
"MessageOutputItem",
"ModelResponse",
"RunItem",
"HandoffCallItem",
"HandoffOutputItem",
"ToolCallItem",
"ToolCallOutputItem",
"ReasoningItem",
"ModelResponse",
"ItemHelpers",
"RunHooks",
"AgentHooks",
"RunContextWrapper",
"TContext",
"RunResult",
"RunResultStreaming",
"RunConfig",
"RawResponsesStreamEvent",
"RunItemStreamEvent",
"AgentUpdatedStreamEvent",
"StreamEvent",
"FunctionTool",
"ComputerTool",
"FileSearchTool",
"Tool",
"WebSearchTool",
"function_tool",
"Usage",
"add_trace_processor",
"agent_span",
"custom_span",
"function_span",
"generation_span",
"get_current_span",
"get_current_trace",
"guardrail_span",
"handoff_span",
"set_trace_processors",
"set_tracing_disabled",
"trace",
"Trace",
"TracingProcessor",
"SpanError",
"Span",
"SpanData",
"AgentSpanData",
"CustomSpanData",
"FunctionSpanData",
"GenerationSpanData",
"GuardrailSpanData",
"HandoffSpanData",
"set_default_openai_key",
"set_default_openai_client",
"set_default_openai_api",
"set_tracing_export_api_key",
"enable_verbose_stdout_logging",
"gen_trace_id",
"gen_span_id",
"default_tool_error_function",
]