vision-agent 0.2.59__py3-none-any.whl → 0.2.60__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.
@@ -8,6 +8,7 @@ from pathlib import Path
8
8
  from typing import Any, Callable, Dict, List, Optional, Sequence, Union, cast
9
9
 
10
10
  from PIL import Image
11
+ from langsmith import traceable
11
12
  from rich.console import Console
12
13
  from rich.style import Style
13
14
  from rich.syntax import Syntax
@@ -130,6 +131,7 @@ def extract_image(
130
131
  return new_media
131
132
 
132
133
 
134
+ @traceable
133
135
  def write_plan(
134
136
  chat: List[Message],
135
137
  tool_desc: str,
@@ -147,6 +149,7 @@ def write_plan(
147
149
  return extract_json(model.chat(chat))["plan"] # type: ignore
148
150
 
149
151
 
152
+ @traceable
150
153
  def write_code(
151
154
  coder: LMM,
152
155
  chat: List[Message],
@@ -167,6 +170,7 @@ def write_code(
167
170
  return extract_code(coder(chat))
168
171
 
169
172
 
173
+ @traceable
170
174
  def write_test(
171
175
  tester: LMM,
172
176
  chat: List[Message],
@@ -191,6 +195,7 @@ def write_test(
191
195
  return extract_code(tester(chat))
192
196
 
193
197
 
198
+ @traceable
194
199
  def reflect(
195
200
  chat: List[Message],
196
201
  plan: str,
@@ -266,70 +271,19 @@ def write_and_test_code(
266
271
  count = 0
267
272
  new_working_memory: List[Dict[str, str]] = []
268
273
  while not result.success and count < max_retries:
269
- log_progress(
270
- {
271
- "type": "code",
272
- "status": "started",
273
- }
274
- )
275
- fixed_code_and_test = extract_json(
276
- debugger(
277
- FIX_BUG.format(
278
- code=code,
279
- tests=test,
280
- result="\n".join(result.text().splitlines()[-50:]),
281
- feedback=format_memory(working_memory + new_working_memory),
282
- )
283
- )
284
- )
285
- old_code = code
286
- old_test = test
287
-
288
- if fixed_code_and_test["code"].strip() != "":
289
- code = extract_code(fixed_code_and_test["code"])
290
- if fixed_code_and_test["test"].strip() != "":
291
- test = extract_code(fixed_code_and_test["test"])
292
-
293
- new_working_memory.append(
294
- {
295
- "code": f"{code}\n{test}",
296
- "feedback": fixed_code_and_test["reflections"],
297
- "edits": get_diff(f"{old_code}\n{old_test}", f"{code}\n{test}"),
298
- }
299
- )
300
- log_progress(
301
- {
302
- "type": "code",
303
- "status": "running",
304
- "payload": {
305
- "code": DefaultImports.prepend_imports(code),
306
- "test": test,
307
- },
308
- }
309
- )
310
-
311
- result = code_interpreter.exec_isolation(
312
- f"{DefaultImports.to_code_string()}\n{code}\n{test}"
313
- )
314
- log_progress(
315
- {
316
- "type": "code",
317
- "status": "completed" if result.success else "failed",
318
- "payload": {
319
- "code": DefaultImports.prepend_imports(code),
320
- "test": test,
321
- "result": result.to_json(),
322
- },
323
- }
324
- )
325
274
  if verbosity == 2:
326
- _LOGGER.info(
327
- f"Debug attempt {count + 1}, reflection: {fixed_code_and_test['reflections']}"
328
- )
329
- _print_code("Code and test after attempted fix:", code, test)
330
- _LOGGER.info(
331
- f"Code execution result after attempted fix: {result.text(include_logs=True)}"
332
- )
275
+ _LOGGER.info(f"Start debugging attempt {count + 1}")
276
+ code, test, result = debug_code(
277
+ working_memory,
278
+ debugger,
279
+ code_interpreter,
280
+ code,
281
+ test,
282
+ result,
283
+ new_working_memory,
284
+ log_progress,
285
+ verbosity,
286
+ )
333
287
  count += 1
334
288
 
335
289
  if verbosity >= 1:
@@ -344,6 +298,83 @@ def write_and_test_code(
344
298
  }
345
299
 
346
300
 
301
+ @traceable
302
+ def debug_code(
303
+ working_memory: List[Dict[str, str]],
304
+ debugger: LMM,
305
+ code_interpreter: CodeInterpreter,
306
+ code: str,
307
+ test: str,
308
+ result: Execution,
309
+ new_working_memory: List[Dict[str, str]],
310
+ log_progress: Callable[[Dict[str, Any]], None],
311
+ verbosity: int = 0,
312
+ ) -> tuple[str, str, Execution]:
313
+ log_progress(
314
+ {
315
+ "type": "code",
316
+ "status": "started",
317
+ }
318
+ )
319
+ fixed_code_and_test = extract_json(
320
+ debugger(
321
+ FIX_BUG.format(
322
+ code=code,
323
+ tests=test,
324
+ result="\n".join(result.text().splitlines()[-50:]),
325
+ feedback=format_memory(working_memory + new_working_memory),
326
+ )
327
+ )
328
+ )
329
+ old_code = code
330
+ old_test = test
331
+
332
+ if fixed_code_and_test["code"].strip() != "":
333
+ code = extract_code(fixed_code_and_test["code"])
334
+ if fixed_code_and_test["test"].strip() != "":
335
+ test = extract_code(fixed_code_and_test["test"])
336
+
337
+ new_working_memory.append(
338
+ {
339
+ "code": f"{code}\n{test}",
340
+ "feedback": fixed_code_and_test["reflections"],
341
+ "edits": get_diff(f"{old_code}\n{old_test}", f"{code}\n{test}"),
342
+ }
343
+ )
344
+ log_progress(
345
+ {
346
+ "type": "code",
347
+ "status": "running",
348
+ "payload": {
349
+ "code": DefaultImports.prepend_imports(code),
350
+ "test": test,
351
+ },
352
+ }
353
+ )
354
+
355
+ result = code_interpreter.exec_isolation(
356
+ f"{DefaultImports.to_code_string()}\n{code}\n{test}"
357
+ )
358
+ log_progress(
359
+ {
360
+ "type": "code",
361
+ "status": "completed" if result.success else "failed",
362
+ "payload": {
363
+ "code": DefaultImports.prepend_imports(code),
364
+ "test": test,
365
+ "result": result.to_json(),
366
+ },
367
+ }
368
+ )
369
+ if verbosity == 2:
370
+ _print_code("Code and test after attempted fix:", code, test)
371
+ _LOGGER.info(
372
+ f"Reflection: {fixed_code_and_test['reflections']}\nCode execution result after attempted fix: {result.text(include_logs=True)}"
373
+ )
374
+
375
+ return code, test, result
376
+
377
+
347
378
  def _print_code(title: str, code: str, test: Optional[str] = None) -> None:
348
379
  _CONSOLE.print(title, style=Style(bgcolor="dark_orange3", bold=True))
349
380
  _CONSOLE.print("=" * 30 + " Code " + "=" * 30)
@@ -481,6 +512,7 @@ class VisionAgent(Agent):
481
512
  results.pop("working_memory")
482
513
  return results # type: ignore
483
514
 
515
+ @traceable
484
516
  def chat_with_workflow(
485
517
  self,
486
518
  chat: List[Message],
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: vision-agent
3
- Version: 0.2.59
3
+ Version: 0.2.60
4
4
  Summary: Toolset for Vision Agent
5
5
  Author: Landing AI
6
6
  Author-email: dev@landing.ai
@@ -9,8 +9,8 @@ Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Programming Language :: Python :: 3.9
10
10
  Classifier: Programming Language :: Python :: 3.10
11
11
  Classifier: Programming Language :: Python :: 3.11
12
- Requires-Dist: e2b (>=0.17.0,<0.18.0)
13
- Requires-Dist: e2b-code-interpreter (>=0.0.7,<0.0.8)
12
+ Requires-Dist: e2b (>=0.17.1,<0.18.0)
13
+ Requires-Dist: e2b-code-interpreter (>=0.0.9,<0.0.10)
14
14
  Requires-Dist: ipykernel (>=6.29.4,<7.0.0)
15
15
  Requires-Dist: langsmith (>=0.1.58,<0.2.0)
16
16
  Requires-Dist: moviepy (>=1.0.0,<2.0.0)
@@ -1,7 +1,7 @@
1
1
  vision_agent/__init__.py,sha256=EAb4-f9iyuEYkBrX4ag1syM8Syx8118_t0R6_C34M9w,57
2
2
  vision_agent/agent/__init__.py,sha256=IUwfbPMcT8X_rnXMLmI8gJ4ltsHy_XSs9eLiKURJxeY,81
3
3
  vision_agent/agent/agent.py,sha256=ZK-5lOtd9-eD9aWcXssJpnOyvZuO7_5hAmnb-6sWVe8,569
4
- vision_agent/agent/vision_agent.py,sha256=QK3G8YdT5vwW5OIh1PN-2gJECFkVNkey-MdK4YdXo-c,24394
4
+ vision_agent/agent/vision_agent.py,sha256=FF71-UucLXANgU1wJrSBRf9zSj1qufWVfaUyzFJ30Ps,24896
5
5
  vision_agent/agent/vision_agent_prompts.py,sha256=bMXdZYf6kbikHn__tCGrYE1QvXC88EmpMpM_97V6szA,8472
6
6
  vision_agent/fonts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  vision_agent/fonts/default_font_ch_en.ttf,sha256=1YM0Z3XqLDjSNbF7ihQFSAIUdjF9m1rtHiNC_6QosTE,1594400
@@ -17,7 +17,7 @@ vision_agent/utils/image_utils.py,sha256=_cdiS5YrLzqkq_ZgFUO897m5M4_SCIThwUy4lOk
17
17
  vision_agent/utils/sim.py,sha256=rGRGnjsy91IOn8qzt7k04PIRj5jyiaQyYAQl7ossPt8,4195
18
18
  vision_agent/utils/type_defs.py,sha256=BlI8ywWHAplC7kYWLvt4AOdnKpEW3qWEFm-GEOSkrFQ,1792
19
19
  vision_agent/utils/video.py,sha256=rNmU9KEIkZB5-EztZNlUiKYN0mm_55A_2VGUM0QpqLA,8779
20
- vision_agent-0.2.59.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
21
- vision_agent-0.2.59.dist-info/METADATA,sha256=nctgSZSHz1AOvXiuxArTsvpgl59EE9NaqRPZLShrar8,7632
22
- vision_agent-0.2.59.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
23
- vision_agent-0.2.59.dist-info/RECORD,,
20
+ vision_agent-0.2.60.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
21
+ vision_agent-0.2.60.dist-info/METADATA,sha256=v050N38ELp01qkOz_KoPRASH9nv3Bq_xVdBkIJBHZ7o,7633
22
+ vision_agent-0.2.60.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
23
+ vision_agent-0.2.60.dist-info/RECORD,,