lmnr 0.5.1a0__py3-none-any.whl → 0.5.3__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.
- lmnr/__init__.py +2 -10
- lmnr/cli.py +10 -8
- lmnr/{openllmetry_sdk → opentelemetry_lib}/__init__.py +8 -36
- lmnr/{openllmetry_sdk → opentelemetry_lib}/decorators/base.py +27 -20
- lmnr/{openllmetry_sdk → opentelemetry_lib}/instruments.py +2 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/__init__.py +454 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/config.py +9 -0
- lmnr/opentelemetry_lib/opentelemetry/instrumentation/google_genai/utils.py +216 -0
- lmnr/opentelemetry_lib/tracing/__init__.py +1 -0
- lmnr/opentelemetry_lib/tracing/context_manager.py +13 -0
- lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/tracing.py +253 -257
- lmnr/sdk/browser/browser_use_otel.py +20 -3
- lmnr/sdk/browser/patchright_otel.py +177 -0
- lmnr/sdk/browser/playwright_otel.py +55 -62
- lmnr/sdk/browser/pw_utils.py +122 -116
- lmnr/sdk/browser/rrweb/rrweb.umd.min.cjs +98 -0
- lmnr/sdk/client/asynchronous/async_client.py +0 -34
- lmnr/sdk/client/asynchronous/resources/__init__.py +0 -4
- lmnr/sdk/client/asynchronous/resources/agent.py +115 -6
- lmnr/sdk/client/synchronous/resources/__init__.py +1 -3
- lmnr/sdk/client/synchronous/resources/agent.py +112 -6
- lmnr/sdk/client/synchronous/sync_client.py +0 -36
- lmnr/sdk/decorators.py +19 -5
- lmnr/sdk/eval_control.py +3 -2
- lmnr/sdk/evaluations.py +8 -14
- lmnr/sdk/laminar.py +10 -10
- lmnr/sdk/types.py +86 -170
- lmnr/sdk/utils.py +8 -1
- lmnr/version.py +1 -1
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/METADATA +58 -58
- lmnr-0.5.3.dist-info/RECORD +55 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/WHEEL +1 -1
- lmnr/openllmetry_sdk/tracing/__init__.py +0 -0
- lmnr/sdk/browser/rrweb/rrweb.min.js +0 -18
- lmnr/sdk/client/asynchronous/resources/pipeline.py +0 -89
- lmnr/sdk/client/asynchronous/resources/semantic_search.py +0 -60
- lmnr/sdk/client/synchronous/resources/pipeline.py +0 -89
- lmnr/sdk/client/synchronous/resources/semantic_search.py +0 -60
- lmnr-0.5.1a0.dist-info/RECORD +0 -54
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/.flake8 +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/config/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/decorators/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/attributes.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/tracing/content_allow_list.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/__init__.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/in_memory_span_exporter.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/json_encoder.py +0 -0
- /lmnr/{openllmetry_sdk → opentelemetry_lib}/utils/package_check.py +0 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/LICENSE +0 -0
- {lmnr-0.5.1a0.dist-info → lmnr-0.5.3.dist-info}/entry_points.txt +0 -0
@@ -11,8 +11,6 @@ from lmnr.sdk.client.asynchronous.resources import (
|
|
11
11
|
AsyncAgent,
|
12
12
|
AsyncBrowserEvents,
|
13
13
|
AsyncEvals,
|
14
|
-
AsyncPipeline,
|
15
|
-
AsyncSemanticSearch,
|
16
14
|
)
|
17
15
|
from lmnr.sdk.utils import from_env
|
18
16
|
|
@@ -66,12 +64,6 @@ class AsyncLaminarClient:
|
|
66
64
|
)
|
67
65
|
|
68
66
|
# Initialize resource objects
|
69
|
-
self.__pipeline = AsyncPipeline(
|
70
|
-
self.__client, self.__base_url, self.__project_api_key
|
71
|
-
)
|
72
|
-
self.__semantic_search = AsyncSemanticSearch(
|
73
|
-
self.__client, self.__base_url, self.__project_api_key
|
74
|
-
)
|
75
67
|
self.__agent = AsyncAgent(
|
76
68
|
self.__client, self.__base_url, self.__project_api_key
|
77
69
|
)
|
@@ -82,24 +74,6 @@ class AsyncLaminarClient:
|
|
82
74
|
self.__client, self.__base_url, self.__project_api_key
|
83
75
|
)
|
84
76
|
|
85
|
-
@property
|
86
|
-
def pipeline(self) -> AsyncPipeline:
|
87
|
-
"""Get the Pipeline resource.
|
88
|
-
|
89
|
-
Returns:
|
90
|
-
Pipeline: The Pipeline resource instance.
|
91
|
-
"""
|
92
|
-
return self.__pipeline
|
93
|
-
|
94
|
-
@property
|
95
|
-
def semantic_search(self) -> AsyncSemanticSearch:
|
96
|
-
"""Get the SemanticSearch resource.
|
97
|
-
|
98
|
-
Returns:
|
99
|
-
SemanticSearch: The SemanticSearch resource instance.
|
100
|
-
"""
|
101
|
-
return self.__semantic_search
|
102
|
-
|
103
77
|
@property
|
104
78
|
def agent(self) -> AsyncAgent:
|
105
79
|
"""Get the Agent resource.
|
@@ -137,14 +111,6 @@ class AsyncLaminarClient:
|
|
137
111
|
"""
|
138
112
|
await self.__client.aclose()
|
139
113
|
|
140
|
-
@property
|
141
|
-
def base_url(self) -> str:
|
142
|
-
return self.__base_url
|
143
|
-
|
144
|
-
@property
|
145
|
-
def project_api_key(self) -> str:
|
146
|
-
return self.__project_api_key
|
147
|
-
|
148
114
|
async def __aenter__(self: _T) -> _T:
|
149
115
|
return self
|
150
116
|
|
@@ -1,12 +1,8 @@
|
|
1
1
|
from lmnr.sdk.client.asynchronous.resources.agent import AsyncAgent
|
2
2
|
from lmnr.sdk.client.asynchronous.resources.browser_events import AsyncBrowserEvents
|
3
3
|
from lmnr.sdk.client.asynchronous.resources.evals import AsyncEvals
|
4
|
-
from lmnr.sdk.client.asynchronous.resources.pipeline import AsyncPipeline
|
5
|
-
from lmnr.sdk.client.asynchronous.resources.semantic_search import AsyncSemanticSearch
|
6
4
|
|
7
5
|
__all__ = [
|
8
|
-
"AsyncPipeline",
|
9
|
-
"AsyncSemanticSearch",
|
10
6
|
"AsyncAgent",
|
11
7
|
"AsyncEvals",
|
12
8
|
"AsyncBrowserEvents",
|
@@ -35,7 +35,18 @@ class AsyncAgent(BaseAsyncResource):
|
|
35
35
|
model_provider: Optional[ModelProvider] = None,
|
36
36
|
model: Optional[str] = None,
|
37
37
|
enable_thinking: bool = True,
|
38
|
+
agent_state: Optional[str] = None,
|
39
|
+
storage_state: Optional[str] = None,
|
38
40
|
return_screenshots: bool = False,
|
41
|
+
return_agent_state: bool = False,
|
42
|
+
return_storage_state: bool = False,
|
43
|
+
disable_give_control: bool = False,
|
44
|
+
timeout: Optional[int] = None,
|
45
|
+
cdp_url: Optional[str] = None,
|
46
|
+
max_steps: Optional[int] = None,
|
47
|
+
thinking_token_budget: Optional[int] = None,
|
48
|
+
start_url: Optional[str] = None,
|
49
|
+
user_agent: Optional[str] = None,
|
39
50
|
) -> AsyncIterator[RunAgentResponseChunk]:
|
40
51
|
"""Run Laminar index agent in streaming mode.
|
41
52
|
|
@@ -46,7 +57,19 @@ class AsyncAgent(BaseAsyncResource):
|
|
46
57
|
model_provider (Optional[ModelProvider], optional): LLM model provider
|
47
58
|
model (Optional[str], optional): LLM model name
|
48
59
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
60
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
61
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
49
62
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
63
|
+
return_agent_state (bool, optional): whether to return the agent's state in the final chunk. Default to False.
|
64
|
+
return_storage_state (bool, optional): whether to return the storage state in the final chunk. Default to False.
|
65
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
66
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
67
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
68
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
69
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
70
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
71
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
72
|
+
|
50
73
|
Returns:
|
51
74
|
AsyncIterator[RunAgentResponseChunk]: a generator of response chunks
|
52
75
|
"""
|
@@ -60,7 +83,18 @@ class AsyncAgent(BaseAsyncResource):
|
|
60
83
|
model_provider: Optional[ModelProvider] = None,
|
61
84
|
model: Optional[str] = None,
|
62
85
|
enable_thinking: bool = True,
|
86
|
+
agent_state: Optional[str] = None,
|
87
|
+
storage_state: Optional[str] = None,
|
63
88
|
return_screenshots: bool = False,
|
89
|
+
return_agent_state: bool = False,
|
90
|
+
return_storage_state: bool = False,
|
91
|
+
disable_give_control: bool = False,
|
92
|
+
timeout: Optional[int] = None,
|
93
|
+
cdp_url: Optional[str] = None,
|
94
|
+
max_steps: Optional[int] = None,
|
95
|
+
thinking_token_budget: Optional[int] = None,
|
96
|
+
start_url: Optional[str] = None,
|
97
|
+
user_agent: Optional[str] = None,
|
64
98
|
) -> AgentOutput:
|
65
99
|
"""Run Laminar index agent.
|
66
100
|
|
@@ -70,7 +104,19 @@ class AsyncAgent(BaseAsyncResource):
|
|
70
104
|
model_provider (Optional[ModelProvider], optional): LLM model provider
|
71
105
|
model (Optional[str], optional): LLM model name
|
72
106
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
107
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
108
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
73
109
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
110
|
+
return_agent_state (bool, optional): whether to return the agent's state. Default to False.
|
111
|
+
return_storage_state (bool, optional): whether to return the storage state. Default to False.
|
112
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
113
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
114
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
115
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
116
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
117
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
118
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
119
|
+
|
74
120
|
Returns:
|
75
121
|
AgentOutput: agent output
|
76
122
|
"""
|
@@ -85,7 +131,17 @@ class AsyncAgent(BaseAsyncResource):
|
|
85
131
|
model: Optional[str] = None,
|
86
132
|
stream: Literal[False] = False,
|
87
133
|
enable_thinking: bool = True,
|
134
|
+
agent_state: Optional[str] = None,
|
135
|
+
storage_state: Optional[str] = None,
|
88
136
|
return_screenshots: bool = False,
|
137
|
+
return_agent_state: bool = False,
|
138
|
+
return_storage_state: bool = False,
|
139
|
+
disable_give_control: bool = False,
|
140
|
+
timeout: Optional[int] = None,
|
141
|
+
max_steps: Optional[int] = None,
|
142
|
+
thinking_token_budget: Optional[int] = None,
|
143
|
+
start_url: Optional[str] = None,
|
144
|
+
user_agent: Optional[str] = None,
|
89
145
|
) -> AgentOutput:
|
90
146
|
"""Run Laminar index agent.
|
91
147
|
|
@@ -96,7 +152,19 @@ class AsyncAgent(BaseAsyncResource):
|
|
96
152
|
model (Optional[str], optional): LLM model name
|
97
153
|
stream (Literal[False], optional): whether to stream the agent's response
|
98
154
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
155
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
156
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
99
157
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
158
|
+
return_agent_state (bool, optional): whether to return the agent's state. Default to False.
|
159
|
+
return_storage_state (bool, optional): whether to return the storage state. Default to False.
|
160
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
161
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
162
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
163
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
164
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
165
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
166
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
167
|
+
|
100
168
|
Returns:
|
101
169
|
AgentOutput: agent output
|
102
170
|
"""
|
@@ -110,7 +178,18 @@ class AsyncAgent(BaseAsyncResource):
|
|
110
178
|
model: Optional[str] = None,
|
111
179
|
stream: bool = False,
|
112
180
|
enable_thinking: bool = True,
|
181
|
+
agent_state: Optional[str] = None,
|
182
|
+
storage_state: Optional[str] = None,
|
113
183
|
return_screenshots: bool = False,
|
184
|
+
return_agent_state: bool = False,
|
185
|
+
return_storage_state: bool = False,
|
186
|
+
disable_give_control: bool = False,
|
187
|
+
timeout: Optional[int] = None,
|
188
|
+
cdp_url: Optional[str] = None,
|
189
|
+
max_steps: Optional[int] = None,
|
190
|
+
thinking_token_budget: Optional[int] = None,
|
191
|
+
start_url: Optional[str] = None,
|
192
|
+
user_agent: Optional[str] = None,
|
114
193
|
) -> Union[AgentOutput, Awaitable[AsyncIterator[RunAgentResponseChunk]]]:
|
115
194
|
"""Run Laminar index agent.
|
116
195
|
|
@@ -121,7 +200,19 @@ class AsyncAgent(BaseAsyncResource):
|
|
121
200
|
model (Optional[str], optional): LLM model name
|
122
201
|
stream (bool, optional): whether to stream the agent's response
|
123
202
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
203
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
204
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
124
205
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
206
|
+
return_agent_state (bool, optional): whether to return the agent's state. Default to False.
|
207
|
+
return_storage_state (bool, optional): whether to return the storage state. Default to False.
|
208
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
209
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
210
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
211
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
212
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
213
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
214
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
215
|
+
|
125
216
|
Returns:
|
126
217
|
Union[AgentOutput, AsyncIterator[RunAgentResponseChunk]]: agent output or a generator of response chunks
|
127
218
|
"""
|
@@ -142,15 +233,25 @@ class AsyncAgent(BaseAsyncResource):
|
|
142
233
|
parent_span_context=parent_span_context,
|
143
234
|
model_provider=model_provider,
|
144
235
|
model=model,
|
145
|
-
|
146
|
-
|
236
|
+
agent_state=agent_state,
|
237
|
+
storage_state=storage_state,
|
238
|
+
# We always connect to stream, because our network configuration
|
239
|
+
# has a hard fixed idle timeout of 350 seconds.
|
147
240
|
# This means that if we don't stream, the connection will be closed.
|
148
241
|
# For now, we just return the content of the final chunk if `stream` is
|
149
242
|
# `False`.
|
150
|
-
# https://aws.amazon.com/blogs/networking-and-content-delivery/introducing-nlb-tcp-configurable-idle-timeout/
|
151
243
|
stream=True,
|
152
244
|
enable_thinking=enable_thinking,
|
153
245
|
return_screenshots=return_screenshots,
|
246
|
+
return_agent_state=return_agent_state,
|
247
|
+
return_storage_state=return_storage_state,
|
248
|
+
disable_give_control=disable_give_control,
|
249
|
+
user_agent=user_agent,
|
250
|
+
timeout=timeout,
|
251
|
+
cdp_url=cdp_url,
|
252
|
+
max_steps=max_steps,
|
253
|
+
thinking_token_budget=thinking_token_budget,
|
254
|
+
start_url=start_url,
|
154
255
|
)
|
155
256
|
|
156
257
|
# For streaming case, use a generator function
|
@@ -174,7 +275,7 @@ class AsyncAgent(BaseAsyncResource):
|
|
174
275
|
async with self._client.stream(
|
175
276
|
"POST",
|
176
277
|
self._base_url + "/v1/agent/run",
|
177
|
-
json=request.
|
278
|
+
json=request.model_dump(by_alias=True),
|
178
279
|
headers=self._headers(),
|
179
280
|
) as response:
|
180
281
|
async for line in response.aiter_lines():
|
@@ -187,6 +288,8 @@ class AsyncAgent(BaseAsyncResource):
|
|
187
288
|
if line:
|
188
289
|
chunk = RunAgentResponseChunk.model_validate_json(line)
|
189
290
|
yield chunk.root
|
291
|
+
if chunk.root.chunk_type in ["finalOutput", "error"]:
|
292
|
+
break
|
190
293
|
|
191
294
|
async def __run_non_streaming(self, request: RunAgentRequest) -> AgentOutput:
|
192
295
|
"""Run agent in non-streaming mode.
|
@@ -202,9 +305,11 @@ class AsyncAgent(BaseAsyncResource):
|
|
202
305
|
async with self._client.stream(
|
203
306
|
"POST",
|
204
307
|
self._base_url + "/v1/agent/run",
|
205
|
-
json=request.
|
308
|
+
json=request.model_dump(by_alias=True),
|
206
309
|
headers=self._headers(),
|
207
310
|
) as response:
|
311
|
+
if response.status_code != 200:
|
312
|
+
raise RuntimeError(await response.read())
|
208
313
|
async for line in response.aiter_lines():
|
209
314
|
line = str(line)
|
210
315
|
if line.startswith("[DONE]"):
|
@@ -214,7 +319,11 @@ class AsyncAgent(BaseAsyncResource):
|
|
214
319
|
line = line[6:]
|
215
320
|
if line:
|
216
321
|
chunk = RunAgentResponseChunk.model_validate_json(line)
|
217
|
-
if chunk.root.
|
322
|
+
if chunk.root.chunk_type == "finalOutput":
|
218
323
|
final_chunk = chunk.root
|
324
|
+
elif chunk.root.chunk_type == "error":
|
325
|
+
raise RuntimeError(chunk.root.error)
|
326
|
+
elif chunk.root.chunk_type == "timeout":
|
327
|
+
raise TimeoutError("Agent timed out")
|
219
328
|
|
220
329
|
return final_chunk.content if final_chunk is not None else AgentOutput()
|
@@ -1,7 +1,5 @@
|
|
1
1
|
from lmnr.sdk.client.synchronous.resources.agent import Agent
|
2
2
|
from lmnr.sdk.client.synchronous.resources.browser_events import BrowserEvents
|
3
3
|
from lmnr.sdk.client.synchronous.resources.evals import Evals
|
4
|
-
from lmnr.sdk.client.synchronous.resources.pipeline import Pipeline
|
5
|
-
from lmnr.sdk.client.synchronous.resources.semantic_search import SemanticSearch
|
6
4
|
|
7
|
-
__all__ = ["
|
5
|
+
__all__ = ["Agent", "Evals", "BrowserEvents"]
|
@@ -27,7 +27,18 @@ class Agent(BaseResource):
|
|
27
27
|
model_provider: Optional[ModelProvider] = None,
|
28
28
|
model: Optional[str] = None,
|
29
29
|
enable_thinking: bool = True,
|
30
|
+
agent_state: Optional[str] = None,
|
31
|
+
storage_state: Optional[str] = None,
|
30
32
|
return_screenshots: bool = False,
|
33
|
+
return_agent_state: bool = False,
|
34
|
+
return_storage_state: bool = False,
|
35
|
+
disable_give_control: bool = False,
|
36
|
+
timeout: Optional[int] = None,
|
37
|
+
cdp_url: Optional[str] = None,
|
38
|
+
max_steps: Optional[int] = None,
|
39
|
+
thinking_token_budget: Optional[int] = None,
|
40
|
+
start_url: Optional[str] = None,
|
41
|
+
user_agent: Optional[str] = None,
|
31
42
|
) -> Generator[RunAgentResponseChunk, None, None]:
|
32
43
|
"""Run Laminar index agent in streaming mode.
|
33
44
|
|
@@ -38,7 +49,18 @@ class Agent(BaseResource):
|
|
38
49
|
model_provider (Optional[ModelProvider], optional): LLM model provider
|
39
50
|
model (Optional[str], optional): LLM model name
|
40
51
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
52
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
53
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
41
54
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
55
|
+
return_agent_state (bool, optional): whether to return the agent's state. Default to False.
|
56
|
+
return_storage_state (bool, optional): whether to return the storage state. Default to False.
|
57
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
58
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
59
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
60
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
61
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
62
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
63
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
42
64
|
Returns:
|
43
65
|
Generator[RunAgentResponseChunk, None, None]: a generator of response chunks
|
44
66
|
"""
|
@@ -52,7 +74,18 @@ class Agent(BaseResource):
|
|
52
74
|
model_provider: Optional[ModelProvider] = None,
|
53
75
|
model: Optional[str] = None,
|
54
76
|
enable_thinking: bool = True,
|
77
|
+
agent_state: Optional[str] = None,
|
78
|
+
storage_state: Optional[str] = None,
|
55
79
|
return_screenshots: bool = False,
|
80
|
+
return_agent_state: bool = False,
|
81
|
+
disable_give_control: bool = False,
|
82
|
+
return_storage_state: bool = False,
|
83
|
+
timeout: Optional[int] = None,
|
84
|
+
cdp_url: Optional[str] = None,
|
85
|
+
max_steps: Optional[int] = None,
|
86
|
+
thinking_token_budget: Optional[int] = None,
|
87
|
+
start_url: Optional[str] = None,
|
88
|
+
user_agent: Optional[str] = None,
|
56
89
|
) -> AgentOutput:
|
57
90
|
"""Run Laminar index agent.
|
58
91
|
|
@@ -62,7 +95,18 @@ class Agent(BaseResource):
|
|
62
95
|
model_provider (Optional[ModelProvider], optional): LLM model provider
|
63
96
|
model (Optional[str], optional): LLM model name
|
64
97
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
98
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
99
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
65
100
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
101
|
+
return_agent_state (bool, optional): whether to return the agent's state. Default to False.
|
102
|
+
return_storage_state (bool, optional): whether to return the storage state. Default to False.
|
103
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
104
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
105
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
106
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
107
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
108
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
109
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
66
110
|
|
67
111
|
Returns:
|
68
112
|
AgentOutput: agent output
|
@@ -78,7 +122,18 @@ class Agent(BaseResource):
|
|
78
122
|
model: Optional[str] = None,
|
79
123
|
stream: Literal[False] = False,
|
80
124
|
enable_thinking: bool = True,
|
125
|
+
agent_state: Optional[str] = None,
|
126
|
+
storage_state: Optional[str] = None,
|
81
127
|
return_screenshots: bool = False,
|
128
|
+
return_agent_state: bool = False,
|
129
|
+
return_storage_state: bool = False,
|
130
|
+
disable_give_control: bool = False,
|
131
|
+
timeout: Optional[int] = None,
|
132
|
+
cdp_url: Optional[str] = None,
|
133
|
+
max_steps: Optional[int] = None,
|
134
|
+
thinking_token_budget: Optional[int] = None,
|
135
|
+
start_url: Optional[str] = None,
|
136
|
+
user_agent: Optional[str] = None,
|
82
137
|
) -> AgentOutput:
|
83
138
|
"""Run Laminar index agent.
|
84
139
|
|
@@ -89,7 +144,18 @@ class Agent(BaseResource):
|
|
89
144
|
model (Optional[str], optional): LLM model name
|
90
145
|
stream (Literal[False], optional): whether to stream the agent's response
|
91
146
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
147
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
148
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
92
149
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
150
|
+
return_agent_state (bool, optional): whether to return the agent's state. Default to False.
|
151
|
+
return_storage_state (bool, optional): whether to return the storage state. Default to False.
|
152
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
153
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
154
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
155
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
156
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
157
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
158
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
93
159
|
|
94
160
|
Returns:
|
95
161
|
AgentOutput: agent output
|
@@ -104,7 +170,18 @@ class Agent(BaseResource):
|
|
104
170
|
model: Optional[str] = None,
|
105
171
|
stream: bool = False,
|
106
172
|
enable_thinking: bool = True,
|
173
|
+
agent_state: Optional[str] = None,
|
174
|
+
storage_state: Optional[str] = None,
|
107
175
|
return_screenshots: bool = False,
|
176
|
+
return_agent_state: bool = False,
|
177
|
+
return_storage_state: bool = False,
|
178
|
+
disable_give_control: bool = False,
|
179
|
+
timeout: Optional[int] = None,
|
180
|
+
cdp_url: Optional[str] = None,
|
181
|
+
max_steps: Optional[int] = None,
|
182
|
+
thinking_token_budget: Optional[int] = None,
|
183
|
+
start_url: Optional[str] = None,
|
184
|
+
user_agent: Optional[str] = None,
|
108
185
|
) -> Union[AgentOutput, Generator[RunAgentResponseChunk, None, None]]:
|
109
186
|
"""Run Laminar index agent.
|
110
187
|
|
@@ -115,7 +192,18 @@ class Agent(BaseResource):
|
|
115
192
|
model (Optional[str], optional): LLM model name
|
116
193
|
stream (bool, optional): whether to stream the agent's response
|
117
194
|
enable_thinking (bool, optional): whether to enable thinking on the underlying LLM. Default to True.
|
195
|
+
agent_state (Optional[str], optional): the agent's state as returned by the previous agent run. Default to None.
|
196
|
+
storage_state (Optional[str], optional): the browser's storage state as returned by the previous agent run. Default to None.
|
118
197
|
return_screenshots (bool, optional): whether to return screenshots of the agent's states at every step. Default to False.
|
198
|
+
return_agent_state (bool, optional): whether to return the agent's state. Default to False.
|
199
|
+
return_storage_state (bool, optional): whether to return the storage state. Default to False.
|
200
|
+
disable_give_control (bool, optional): whether to NOT give the agent additional direction to give control to the user for tasks such as login. Default to False.
|
201
|
+
timeout (Optional[int], optional): timeout seconds for the agent's response. Default to None.
|
202
|
+
cdp_url (Optional[str], optional): Chrome DevTools Protocol URL of an existing browser session. Default to None.
|
203
|
+
max_steps (Optional[int], optional): maximum number of steps the agent can take. If not set, the backend will use a default value (currently 100). Default to None.
|
204
|
+
thinking_token_budget (Optional[int], optional): maximum number of tokens the underlying LLM can spend on thinking in each step, if supported by the model. Default to None.
|
205
|
+
start_url (Optional[str], optional): the URL to start the agent on. Must be a valid URL - refer to https://playwright.dev/docs/api/class-page#page-goto. If not specified, the agent infers this from the prompt. Default to None.
|
206
|
+
user_agent (Optional[str], optional): the user to be sent to the browser. If not specified, Laminar uses the default user agent. Default to None.
|
119
207
|
|
120
208
|
Returns:
|
121
209
|
Union[AgentOutput, Generator[RunAgentResponseChunk, None, None]]: agent output or a generator of response chunks
|
@@ -137,15 +225,25 @@ class Agent(BaseResource):
|
|
137
225
|
parent_span_context=parent_span_context,
|
138
226
|
model_provider=model_provider,
|
139
227
|
model=model,
|
140
|
-
|
141
|
-
|
228
|
+
agent_state=agent_state,
|
229
|
+
storage_state=storage_state,
|
230
|
+
# We always connect to stream, because our network configuration
|
231
|
+
# has a hard fixed idle timeout of 350 seconds.
|
142
232
|
# This means that if we don't stream, the connection will be closed.
|
143
233
|
# For now, we just return the content of the final chunk if `stream` is
|
144
234
|
# `False`.
|
145
|
-
# https://aws.amazon.com/blogs/networking-and-content-delivery/introducing-nlb-tcp-configurable-idle-timeout/
|
146
235
|
stream=True,
|
147
236
|
enable_thinking=enable_thinking,
|
148
237
|
return_screenshots=return_screenshots,
|
238
|
+
return_agent_state=return_agent_state,
|
239
|
+
return_storage_state=return_storage_state,
|
240
|
+
timeout=timeout,
|
241
|
+
cdp_url=cdp_url,
|
242
|
+
max_steps=max_steps,
|
243
|
+
thinking_token_budget=thinking_token_budget,
|
244
|
+
start_url=start_url,
|
245
|
+
disable_give_control=disable_give_control,
|
246
|
+
user_agent=user_agent,
|
149
247
|
)
|
150
248
|
|
151
249
|
# For streaming case, use a generator function
|
@@ -169,7 +267,7 @@ class Agent(BaseResource):
|
|
169
267
|
with self._client.stream(
|
170
268
|
"POST",
|
171
269
|
self._base_url + "/v1/agent/run",
|
172
|
-
json=request.
|
270
|
+
json=request.model_dump(by_alias=True),
|
173
271
|
headers=self._headers(),
|
174
272
|
) as response:
|
175
273
|
for line in response.iter_lines():
|
@@ -182,6 +280,8 @@ class Agent(BaseResource):
|
|
182
280
|
if line:
|
183
281
|
chunk = RunAgentResponseChunk.model_validate_json(line)
|
184
282
|
yield chunk.root
|
283
|
+
if chunk.root.chunk_type in ["finalOutput", "error"]:
|
284
|
+
break
|
185
285
|
|
186
286
|
def __run_non_streaming(self, request: RunAgentRequest) -> AgentOutput:
|
187
287
|
"""Run agent in non-streaming mode.
|
@@ -197,9 +297,11 @@ class Agent(BaseResource):
|
|
197
297
|
with self._client.stream(
|
198
298
|
"POST",
|
199
299
|
self._base_url + "/v1/agent/run",
|
200
|
-
json=request.
|
300
|
+
json=request.model_dump(by_alias=True),
|
201
301
|
headers=self._headers(),
|
202
302
|
) as response:
|
303
|
+
if response.status_code != 200:
|
304
|
+
raise RuntimeError(response.read())
|
203
305
|
for line in response.iter_lines():
|
204
306
|
line = str(line)
|
205
307
|
if line.startswith("[DONE]"):
|
@@ -209,7 +311,11 @@ class Agent(BaseResource):
|
|
209
311
|
line = line[6:]
|
210
312
|
if line:
|
211
313
|
chunk = RunAgentResponseChunk.model_validate_json(line)
|
212
|
-
if chunk.root.
|
314
|
+
if chunk.root.chunk_type == "finalOutput":
|
213
315
|
final_chunk = chunk.root
|
316
|
+
elif chunk.root.chunk_type == "error":
|
317
|
+
raise RuntimeError(chunk.root.error)
|
318
|
+
elif chunk.root.chunk_type == "timeout":
|
319
|
+
raise TimeoutError("Agent timed out")
|
214
320
|
|
215
321
|
return final_chunk.content if final_chunk is not None else AgentOutput()
|
@@ -11,8 +11,6 @@ from lmnr.sdk.client.synchronous.resources import (
|
|
11
11
|
Agent,
|
12
12
|
BrowserEvents,
|
13
13
|
Evals,
|
14
|
-
Pipeline,
|
15
|
-
SemanticSearch,
|
16
14
|
)
|
17
15
|
from lmnr.sdk.utils import from_env
|
18
16
|
|
@@ -25,8 +23,6 @@ class LaminarClient:
|
|
25
23
|
__client: httpx.Client = None
|
26
24
|
|
27
25
|
# Resource properties
|
28
|
-
__pipeline: Optional[Pipeline] = None
|
29
|
-
__semantic_search: Optional[SemanticSearch] = None
|
30
26
|
__agent: Optional[Agent] = None
|
31
27
|
__evals: Optional[Evals] = None
|
32
28
|
|
@@ -71,36 +67,12 @@ class LaminarClient:
|
|
71
67
|
)
|
72
68
|
|
73
69
|
# Initialize resource objects
|
74
|
-
self.__pipeline = Pipeline(
|
75
|
-
self.__client, self.__base_url, self.__project_api_key
|
76
|
-
)
|
77
|
-
self.__semantic_search = SemanticSearch(
|
78
|
-
self.__client, self.__base_url, self.__project_api_key
|
79
|
-
)
|
80
70
|
self.__agent = Agent(self.__client, self.__base_url, self.__project_api_key)
|
81
71
|
self.__evals = Evals(self.__client, self.__base_url, self.__project_api_key)
|
82
72
|
self.__browser_events = BrowserEvents(
|
83
73
|
self.__client, self.__base_url, self.__project_api_key
|
84
74
|
)
|
85
75
|
|
86
|
-
@property
|
87
|
-
def pipeline(self) -> Pipeline:
|
88
|
-
"""Get the Pipeline resource.
|
89
|
-
|
90
|
-
Returns:
|
91
|
-
Pipeline: The Pipeline resource instance.
|
92
|
-
"""
|
93
|
-
return self.__pipeline
|
94
|
-
|
95
|
-
@property
|
96
|
-
def semantic_search(self) -> SemanticSearch:
|
97
|
-
"""Get the SemanticSearch resource.
|
98
|
-
|
99
|
-
Returns:
|
100
|
-
SemanticSearch: The SemanticSearch resource instance.
|
101
|
-
"""
|
102
|
-
return self.__semantic_search
|
103
|
-
|
104
76
|
@property
|
105
77
|
def agent(self) -> Agent:
|
106
78
|
"""Get the Agent resource.
|
@@ -150,14 +122,6 @@ class LaminarClient:
|
|
150
122
|
if hasattr(self, "_client"):
|
151
123
|
self.__client.close()
|
152
124
|
|
153
|
-
@property
|
154
|
-
def base_url(self) -> str:
|
155
|
-
return self.__base_url
|
156
|
-
|
157
|
-
@property
|
158
|
-
def project_api_key(self) -> str:
|
159
|
-
return self.__project_api_key
|
160
|
-
|
161
125
|
def __enter__(self: _T) -> _T:
|
162
126
|
return self
|
163
127
|
|
lmnr/sdk/decorators.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
from lmnr.
|
1
|
+
from lmnr.opentelemetry_lib.decorators.base import (
|
2
2
|
entity_method,
|
3
3
|
aentity_method,
|
4
4
|
)
|
@@ -7,8 +7,8 @@ from opentelemetry.trace import INVALID_SPAN, get_current_span
|
|
7
7
|
from typing import Callable, Literal, Optional, TypeVar, Union, cast
|
8
8
|
from typing_extensions import ParamSpec
|
9
9
|
|
10
|
-
from lmnr.
|
11
|
-
from lmnr.
|
10
|
+
from lmnr.opentelemetry_lib.tracing.attributes import SESSION_ID
|
11
|
+
from lmnr.opentelemetry_lib.tracing.tracing import update_association_properties
|
12
12
|
|
13
13
|
from .utils import is_async
|
14
14
|
|
@@ -24,6 +24,7 @@ def observe(
|
|
24
24
|
ignore_input: bool = False,
|
25
25
|
ignore_output: bool = False,
|
26
26
|
span_type: Union[Literal["DEFAULT"], Literal["LLM"], Literal["TOOL"]] = "DEFAULT",
|
27
|
+
ignore_inputs: Optional[list[str]] = None,
|
27
28
|
) -> Callable[[Callable[P, R]], Callable[P, R]]:
|
28
29
|
"""The main decorator entrypoint for Laminar. This is used to wrap
|
29
30
|
functions and methods to create spans.
|
@@ -32,9 +33,20 @@ def observe(
|
|
32
33
|
name (Optional[str], optional): Name of the span. Function
|
33
34
|
name is used if not specified.
|
34
35
|
Defaults to None.
|
35
|
-
session_id (Optional[str], optional): Session ID to associate with the
|
36
|
+
session_id (Optional[str], optional): Session ID to associate with the\
|
36
37
|
span and the following context. Defaults to None.
|
37
|
-
|
38
|
+
ignore_input (bool, optional): Whether to ignore ALL input of the\
|
39
|
+
wrapped function. Defaults to False.
|
40
|
+
ignore_output (bool, optional): Whether to ignore ALL output of the\
|
41
|
+
wrapped function. Defaults to False.
|
42
|
+
span_type (Union[Literal["DEFAULT"], Literal["LLM"], Literal["TOOL"]], optional): Type of the span.
|
43
|
+
Defaults to "DEFAULT".
|
44
|
+
ignore_inputs (Optional[list[str]], optional): List of input keys to ignore.
|
45
|
+
For example, if the wrapped function takes three arguments,\
|
46
|
+
def foo(a, b, `sensitive_data`), and you want to ignore the\
|
47
|
+
`sensitive_data` argument, you can pass ["sensitive_data"] to\
|
48
|
+
this argument.
|
49
|
+
Defaults to None.
|
38
50
|
Raises:
|
39
51
|
Exception: re-raises the exception if the wrapped function raises
|
40
52
|
an exception
|
@@ -58,6 +70,7 @@ def observe(
|
|
58
70
|
ignore_input=ignore_input,
|
59
71
|
ignore_output=ignore_output,
|
60
72
|
span_type=span_type,
|
73
|
+
ignore_inputs=ignore_inputs,
|
61
74
|
)(func)
|
62
75
|
if is_async(func)
|
63
76
|
else entity_method(
|
@@ -65,6 +78,7 @@ def observe(
|
|
65
78
|
ignore_input=ignore_input,
|
66
79
|
ignore_output=ignore_output,
|
67
80
|
span_type=span_type,
|
81
|
+
ignore_inputs=ignore_inputs,
|
68
82
|
)(func)
|
69
83
|
)
|
70
84
|
|