jupyter-agent 2025.6.104__py3-none-any.whl → 2025.6.105__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 (41) hide show
  1. jupyter_agent/bot_actions.py +270 -0
  2. jupyter_agent/bot_agents/__init__.py +0 -42
  3. jupyter_agent/bot_agents/base.py +85 -45
  4. jupyter_agent/bot_agents/master_planner.py +2 -0
  5. jupyter_agent/bot_agents/output_task_result.py +6 -7
  6. jupyter_agent/bot_agents/request_user_supply.py +186 -0
  7. jupyter_agent/bot_agents/task_planner_v3.py +12 -13
  8. jupyter_agent/bot_agents/task_reasoner.py +2 -2
  9. jupyter_agent/bot_agents/task_structrue_reasoner.py +19 -12
  10. jupyter_agent/bot_agents/task_structrue_summarier.py +19 -18
  11. jupyter_agent/bot_agents/task_summarier.py +2 -2
  12. jupyter_agent/bot_agents/task_verifier.py +1 -1
  13. jupyter_agent/bot_agents/task_verify_summarier.py +5 -6
  14. jupyter_agent/bot_chat.py +2 -2
  15. jupyter_agent/bot_contexts.py +28 -23
  16. jupyter_agent/bot_evaluation.py +262 -143
  17. jupyter_agent/bot_evaluators/__init__.py +0 -0
  18. jupyter_agent/bot_evaluators/base.py +42 -0
  19. jupyter_agent/bot_evaluators/dummy_flow.py +20 -0
  20. jupyter_agent/bot_evaluators/dummy_global.py +20 -0
  21. jupyter_agent/bot_evaluators/dummy_task.py +20 -0
  22. jupyter_agent/bot_evaluators/flow_global_planning.py +88 -0
  23. jupyter_agent/bot_evaluators/flow_task_executor.py +152 -0
  24. jupyter_agent/bot_flows/__init__.py +0 -4
  25. jupyter_agent/bot_flows/base.py +84 -19
  26. jupyter_agent/bot_flows/master_planner.py +6 -2
  27. jupyter_agent/bot_flows/task_executor_v3.py +31 -17
  28. jupyter_agent/bot_magics.py +88 -65
  29. jupyter_agent/bot_outputs.py +37 -43
  30. jupyter_agent/utils.py +20 -31
  31. {jupyter_agent-2025.6.104.dist-info → jupyter_agent-2025.6.105.dist-info}/METADATA +34 -4
  32. jupyter_agent-2025.6.105.dist-info/RECORD +40 -0
  33. jupyter_agent/bot_agents/task_planner_v1.py +0 -158
  34. jupyter_agent/bot_agents/task_planner_v2.py +0 -172
  35. jupyter_agent/bot_flows/task_executor_v1.py +0 -86
  36. jupyter_agent/bot_flows/task_executor_v2.py +0 -84
  37. jupyter_agent-2025.6.104.dist-info/RECORD +0 -35
  38. {jupyter_agent-2025.6.104.dist-info → jupyter_agent-2025.6.105.dist-info}/WHEEL +0 -0
  39. {jupyter_agent-2025.6.104.dist-info → jupyter_agent-2025.6.105.dist-info}/entry_points.txt +0 -0
  40. {jupyter_agent-2025.6.104.dist-info → jupyter_agent-2025.6.105.dist-info}/licenses/LICENSE +0 -0
  41. {jupyter_agent-2025.6.104.dist-info → jupyter_agent-2025.6.105.dist-info}/top_level.txt +0 -0
@@ -11,9 +11,11 @@ import datetime
11
11
  import jinja2
12
12
 
13
13
  from enum import Enum
14
- from typing import Optional, Dict, Any
14
+ from typing import Optional, Dict, List, Tuple, Any, Type
15
15
  from pydantic import BaseModel, Field
16
16
  from IPython.display import display, Markdown
17
+ from .bot_evaluation import BaseEvaluationRecord
18
+ from .bot_actions import ActionBase
17
19
  from .utils import no_indent, no_wrap
18
20
 
19
21
  STAGE_SWITCHER_SCRIPT = no_wrap(
@@ -173,38 +175,6 @@ LOGGING_LEVELS = {
173
175
  }
174
176
 
175
177
 
176
- class BaseEvalutionRecord(BaseModel):
177
- timestamp: float = 0
178
- notebook_name: str = ""
179
- eval_type: str = "BASE"
180
- cell_index: int = -1
181
- execution_duration: float = 0.0
182
- is_success: bool = False
183
- correct_score: float = 0.0
184
-
185
-
186
- class StageEvalutionRecord(BaseEvalutionRecord):
187
- eval_type: str = "STAGE"
188
- flow: str = ""
189
- stage: str = ""
190
- coding_score: float = 0.0
191
- important_score: float = 0.0
192
- user_supply_score: float = 0.0
193
-
194
-
195
- class FlowEvalutionRecord(BaseEvalutionRecord):
196
- eval_type: str = "FLOW"
197
- flow: str = ""
198
- stage_count: int = 0
199
- planning_score: float = 0.0
200
-
201
-
202
- class NotebookEvalutionRecord(BaseEvalutionRecord):
203
- eval_type: str = "NOTEBOOK"
204
- flow_count: int = 0
205
- planning_score: float = 0.0
206
-
207
-
208
178
  class AgentOutput:
209
179
  """
210
180
  AgentOutput 是一个用于在 Jupyter Notebook 中显示 Agent 输出的类。
@@ -221,6 +191,7 @@ class AgentOutput:
221
191
  )
222
192
  self.template = self.jinja_env.from_string(AGENT_OUTPUT_TEMPLEATE)
223
193
  self.handler = None
194
+ self._is_dirty = True
224
195
  self._latest_display_tm = 0
225
196
  self._contents = {}
226
197
  self._active_stage = None
@@ -228,6 +199,7 @@ class AgentOutput:
228
199
  self._agent_data = {}
229
200
  self._logging_records = []
230
201
  self._evaluation_records = []
202
+ self._action_records = []
231
203
 
232
204
  @property
233
205
  def content(self):
@@ -263,11 +235,16 @@ class AgentOutput:
263
235
  )
264
236
  if self._evaluation_records:
265
237
  metadata["jupyter-agent-evaluation-records"] = [record.model_dump() for record in self._evaluation_records]
238
+ if self._action_records:
239
+ metadata["jupyter-agent-action-records"] = [record.model_dump() for record in self._action_records]
266
240
  return metadata
267
241
 
268
242
  def display(self, stage=None, force=False, wait=True):
269
- if stage is not None:
243
+ if stage is not None and stage != self._active_stage:
270
244
  self._active_stage = stage
245
+ self._is_dirty = True
246
+ if not self._is_dirty and not force:
247
+ return
271
248
  if not force and time.time() - self._latest_display_tm < 1:
272
249
  if wait:
273
250
  time.sleep(1 - (time.time() - self._latest_display_tm))
@@ -278,6 +255,7 @@ class AgentOutput:
278
255
  else:
279
256
  self.handler.update(Markdown(self.content), metadata=self.metadata)
280
257
  self._latest_display_tm = time.time()
258
+ self._is_dirty = False
281
259
 
282
260
  def clear(self, stage=None, clear_metadata=False):
283
261
  if stage is None:
@@ -286,6 +264,7 @@ class AgentOutput:
286
264
  self._contents[stage] = []
287
265
  if clear_metadata:
288
266
  self._agent_data = {}
267
+ self._is_dirty = True
289
268
  self.display(force=False, wait=False)
290
269
 
291
270
  def output_block(
@@ -305,6 +284,7 @@ class AgentOutput:
305
284
  "code_language": code_language,
306
285
  }
307
286
  )
287
+ self._is_dirty = True
308
288
  self.display(stage, force=False, wait=False)
309
289
 
310
290
  def output_text(self, content, stage=None, code_language="python"):
@@ -320,6 +300,7 @@ class AgentOutput:
320
300
  self._contents[stage][-1]["content"] += "\n" + content
321
301
  else:
322
302
  self._contents[stage].append({"type": "text", "content": content, "code_language": code_language})
303
+ self._is_dirty = True
323
304
  self.display(stage, force=False, wait=False)
324
305
 
325
306
  def output_markdown(self, content, stage=None):
@@ -328,12 +309,14 @@ class AgentOutput:
328
309
  if stage not in self._contents:
329
310
  self._contents[stage] = []
330
311
  self._contents[stage].append({"type": "markdown", "content": content})
312
+ self._is_dirty = True
331
313
  self.display(stage, force=False, wait=False)
332
314
 
333
315
  def output_agent_data(self, **kwargs):
334
316
  self.log(f"output agent data {kwargs}", level="DEBUG")
335
317
  self._agent_data.update(kwargs)
336
- self._agent_data_timestamp = int(time.time() * 1000)
318
+ self._agent_data_timestamp = time.time()
319
+ self._is_dirty = True
337
320
  self.display(force=False, wait=False)
338
321
 
339
322
  def log(self, msg, level="INFO"):
@@ -355,11 +338,12 @@ class AgentOutput:
355
338
  "content": content,
356
339
  }
357
340
  )
341
+ self._is_dirty = True
358
342
  self.display(force=False, wait=False)
359
343
 
360
- def log_evaluation(self, record: BaseEvalutionRecord):
344
+ def log_evaluation(self, record: BaseEvaluationRecord):
361
345
  assert isinstance(
362
- record, BaseEvalutionRecord
346
+ record, BaseEvaluationRecord
363
347
  ), "record must be an instance of BaseEvalutionRecord or its subclass"
364
348
  if record.timestamp == 0:
365
349
  record.timestamp = time.time()
@@ -369,6 +353,16 @@ class AgentOutput:
369
353
  f"success: {record.is_success} correct: {record.correct_score:.2f}",
370
354
  level="INFO",
371
355
  )
356
+ self._is_dirty = True
357
+ self.display(force=False, wait=False)
358
+
359
+ def log_action(self, record: ActionBase):
360
+ assert isinstance(record, ActionBase), "record must be an instance of BaseActionRecord or its subclass"
361
+ if record.timestamp == 0:
362
+ record.timestamp = time.time()
363
+ self._action_records.append(record)
364
+ self.log(f"Action: {record.action} from {record.source}", level="INFO")
365
+ self._is_dirty = True
372
366
  self.display(force=False, wait=False)
373
367
 
374
368
 
@@ -414,14 +408,14 @@ def output_agent_data(**kwargs):
414
408
  get_output().output_agent_data(**kwargs)
415
409
 
416
410
 
417
- def output_evaluation(record: BaseEvalutionRecord):
418
- """
419
- 输出评估记录到 AgentOutput 中。
420
- :param record: 评估记录对象,必须是 BaseEvalutionRecord 的子类。
421
- """
411
+ def output_evaluation(record: BaseEvaluationRecord):
422
412
  get_output().log_evaluation(record)
423
413
 
424
414
 
415
+ def output_action(record: ActionBase):
416
+ get_output().log_action(record)
417
+
418
+
425
419
  def clear_output(stage=None, clear_metadata=False):
426
420
  get_output().clear(stage, clear_metadata)
427
421
 
@@ -534,6 +528,6 @@ _A = output_agent_data
534
528
  _L = log
535
529
  _D = lambda msg: log(msg, level="DEBUG")
536
530
  _I = lambda msg: log(msg, level="INFO")
537
- _W = lambda msg: log(msg, level="WARNING")
531
+ _W = lambda msg: log(msg, level="WARN")
538
532
  _E = lambda msg: log(msg, level="ERROR")
539
533
  _F = lambda msg: log(msg, level="FATAL")
jupyter_agent/utils.py CHANGED
@@ -91,37 +91,6 @@ class TeeOutputCapture(capture_output):
91
91
  return CapturedIO(stdout, stderr, outputs)
92
92
 
93
93
 
94
- class RequestUserPrompt(BaseModel):
95
- prompt: str = Field(
96
- description="需要用户补充详细信息的Prompt",
97
- examples=["请补充与...相关的详细的信息", "请确认...是否...", "请提供..."],
98
- )
99
- example: Optional[str] = Field(None, description="示例", examples=["..."])
100
-
101
-
102
- class UserPromptResponse(BaseModel):
103
- prompt: str = Field(description="需要用户补充详细信息的Prompt", examples=["..."])
104
- response: str = Field(description="用户补充的详细信息", examples=["..."])
105
-
106
-
107
- def request_user_response(prompts: list[RequestUserPrompt]) -> list[UserPromptResponse]:
108
- responses = []
109
- for prompt in prompts:
110
- response = input(f"{prompt.prompt} (例如: {prompt.example})")
111
- responses.append(UserPromptResponse(prompt=prompt.prompt, response=response))
112
- return responses
113
-
114
-
115
- def format_user_prompts(prompts: list[RequestUserPrompt], title="用户补充详细信息") -> str:
116
- result = "```markdown\n"
117
- result += f"### {title}\n\n"
118
- result += "\n".join(
119
- [f"- **Issue**: {prompt.prompt} (例如: {prompt.example})\n- **Reply**: " for prompt in prompts]
120
- )
121
- result += "\n```\n"
122
- return result
123
-
124
-
125
94
  def no_indent(text: str) -> str:
126
95
  return re.sub(r"^\s+", "", text, flags=re.MULTILINE)
127
96
 
@@ -136,3 +105,23 @@ def no_newline(text: str) -> str:
136
105
 
137
106
  def no_space(text: str) -> str:
138
107
  return re.sub(r"\s+", "", text, flags=re.MULTILINE)
108
+
109
+
110
+ class EnvironmentCapbilities(BaseModel):
111
+ save_metadata: bool = False
112
+ user_confirm: bool = False
113
+ user_supply_info: bool = False
114
+ set_cell_content: bool = False
115
+
116
+
117
+ __env_capbilities = EnvironmentCapbilities()
118
+
119
+
120
+ def get_env_capbilities() -> EnvironmentCapbilities:
121
+ return __env_capbilities
122
+
123
+
124
+ def set_env_capbilities(env_capbilities: EnvironmentCapbilities):
125
+ global __env_capbilities
126
+
127
+ __env_capbilities = env_capbilities
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: jupyter-agent
3
- Version: 2025.6.104
3
+ Version: 2025.6.105
4
4
  Summary: 调用LLM实现Jupyter代码的自动生成、执行、调试等功能
5
5
  Author: viewstar000
6
6
  License: MIT
@@ -10,6 +10,7 @@ Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.12
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE
13
+ Requires-Dist: bottle
13
14
  Requires-Dist: ipynbname
14
15
  Requires-Dist: ipython
15
16
  Requires-Dist: jinja2
@@ -95,15 +96,21 @@ pip install /path/to/jupyter-agent/dist/jupyter_agent-xxxx-py3-none-any.whl
95
96
  # 设置当前Notebook的路径,当无法自动获取时需要手工指定,以Vscode中的Notebook为例
96
97
  %config BotMagics.notebook_path = globals()["__vsc_ipynb_file__"]
97
98
 
98
- # 设置是否保存任务数据到Metadata,只有Vscode中安装了jupyter-agent-extension后才支持
99
+ # 设置运行环境是否保存任务数据到Metadata,默认为False,仅在Vscode中安装jupyter-agent-extension后或在评估模式下支持
99
100
  %config BotMagics.support_save_meta = True
101
+ # 设置运行环境是否设置单元格内容,默认为False,权在Vscode中安装jupyter-agent-extension后或在评估模式下支持
102
+ %config BotMagics.support_set_cell_content = True
100
103
 
101
104
  # 设置日志级别,可选值为DEBUG、INFO、WARN、ERROR、FATAL,默认为INFO
102
105
  %config BotMagics.logging_level = 'DEBUG'
103
106
 
107
+ # 开启自动评估功能,默认为False,调用LLM对当前结果进行打分,目前仅实现了对子任务的整体打分
108
+ %config BotMagics.enable_evaluating = True
109
+ # 开启模拟用户补充信息功能,默认为False,调用LLM模拟对Agent的提问进行补充,用于自动评估
110
+ %config BotMagics.enable_supply_mocking = True
111
+
104
112
  # 设置是否显示思考过程,默认为True
105
113
  %config BotMagics.display_think = True
106
-
107
114
  # 设置是否显示发送给出LLM的消息和LLM的回答,默认为False
108
115
  %config BotMagics.display_message = True
109
116
  %config BotMagics.display_response = True
@@ -151,6 +158,14 @@ pip install /path/to/jupyter-agent/dist/jupyter_agent-xxxx-py3-none-any.whl
151
158
 
152
159
  更详细用法可参考[示例Notebook](https://github.com/viewstar000/jupyter-agent/blob/main/examples/data_loader.ipynb)
153
160
 
161
+ ### 评估模式
162
+
163
+ 工具提供了`bot_eval`命令用于在评估模式下执行notebook。在评估模式下,工具会顺序执行所有有单元格,直到例全局目标完成。
164
+
165
+ ```bash
166
+ bot_eval [-o output_eval.ipynb] [-e output_eval.jsonl] input.ipynb
167
+ ```
168
+
154
169
  ## 贡献
155
170
 
156
171
  欢迎提交 issue 或 pull request 参与贡献。
@@ -237,12 +252,19 @@ Advanced Configuration:
237
252
  # Set the current notebook path, when it is not automatically obtained, it needs to be manually specified, for example, in Vscode Notebook
238
253
  %config BotMagics.notebook_path = globals()["__vsc_ipynb_file__"]
239
254
 
240
- # Set whether to save task data to Metadata, only Vscode installed with jupyter-agent-extension supports
255
+ # Set whether to save task data to Metadata, only Vscode installed with jupyter-agent-extension or evaluation mode supports this.
241
256
  %config BotMagics.support_save_meta = True
257
+ # Set whether to set cell content, only Vscode installed with jupyter-agent-extension or evaluation mode supports this.
258
+ %config BotMagics.support_set_cell_content = True
242
259
 
243
260
  # Set the log level, available values are DEBUG、INFO、WARN、ERROR、FATAL, default is INFO
244
261
  %config BotMagics.logging_level = 'DEBUG'
245
262
 
263
+ # Enable automatic evaluation, default is False, call LLM to evaluate the overall result of the subtask
264
+ %config BotMagics.enable_evaluating = True
265
+ # Enable the simulation of user filling in information, default is False, call LLM to simulate the question of the agent to fill in
266
+ %config BotMagics.enable_supply_mocking = True
267
+
246
268
  # Set whether to display thinking process, default is True
247
269
  %config BotMagics.display_think = True
248
270
 
@@ -290,6 +312,14 @@ After generating code for a subtask, the tool will call the corresponding agent
290
312
 
291
313
  For more details, please refer to [example notebook](https://github.com/viewstar000/jupyter-agent/blob/main/examples/data_loader.ipynb)
292
314
 
315
+ ### Evaluation mode
316
+
317
+ Use `bot_eval` command to evaluate the code generated by the agent in evaluation mode. The evaluation mode will execute all cells in order and stop when the global goal is completed.
318
+
319
+ ```python
320
+ bot_eval [-o output_eval.ipynb] [-e output_eval.jsonl] input.ipynb
321
+ ```
322
+
293
323
  ## Contributing
294
324
 
295
325
  Welcome to submit issues or pull requests to participate in contributions.
@@ -0,0 +1,40 @@
1
+ jupyter_agent/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ jupyter_agent/bot_actions.py,sha256=Zq9_nfh4SJdMxkjqcTyQzS0RY4RwofaRkGq_4aexO2o,8453
3
+ jupyter_agent/bot_chat.py,sha256=4zjkHtyOabT1bvGO-n4ZTMw0XREU_XDlgfLCI5gpxsw,8834
4
+ jupyter_agent/bot_contexts.py,sha256=f9PmrA8dTH8v4WLdNL_ZSMJUzMVLuRldLWYwL4vXQ6c,19489
5
+ jupyter_agent/bot_evaluation.py,sha256=t4SH6Gq4BmSyyRMozyQ2623XNGmgtCi9CTNRvOqzuRM,14266
6
+ jupyter_agent/bot_magics.py,sha256=fOStbhYwg60hUbuZwqYIbMrn_TBg0JfTwFT92pysUFw,9869
7
+ jupyter_agent/bot_outputs.py,sha256=QDzReXLqZsU7RAPR4F9JEotxAtIe9YA3ZklCJ9U_jVg,16239
8
+ jupyter_agent/utils.py,sha256=8XKXXZB1EgCwIJEqYJigA8C84FzVTc2xdcF-y5kO3kY,3634
9
+ jupyter_agent/bot_agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ jupyter_agent/bot_agents/base.py,sha256=FwCl1Z9E-nIL99qheGEcKO0H_PEd0I9OzEXd23cmQrg,12308
11
+ jupyter_agent/bot_agents/master_planner.py,sha256=aXXgtyarBmDFNAypdEbpQoxzgGkU-botX7bE9q9w3sM,1392
12
+ jupyter_agent/bot_agents/output_task_result.py,sha256=4DeAmDzjUI_0yfb26f5sLIwa74aJRzEQXbMRSyYMv1g,761
13
+ jupyter_agent/bot_agents/request_user_supply.py,sha256=wL_DyIWPd5-Jdq0boTCAhF-nxf_gPmzXgSPM6jOBFFU,6128
14
+ jupyter_agent/bot_agents/task_code_executor.py,sha256=M3oeEBlmsNz89f-yk3_nzsWKGH2C0o7AH059D_J94D8,2206
15
+ jupyter_agent/bot_agents/task_coder.py,sha256=7fXq9nk1yH3F_mJfCMZBktHmxGfgmpuChMQbpEuL0w4,1783
16
+ jupyter_agent/bot_agents/task_debuger.py,sha256=77pa_Awgvzxm3XkFA1oZsGr8SPJkjApKMtkmoySShmI,1367
17
+ jupyter_agent/bot_agents/task_planner_v3.py,sha256=qrvgfsgWs-tD8L1NWzyv9-fwamNTEm6etJYBy-Ipz28,8487
18
+ jupyter_agent/bot_agents/task_reasoner.py,sha256=OHYzPEb1e4eOGdKfo9655tTEdZRqz-s-Vdgp-2G0Jxc,1425
19
+ jupyter_agent/bot_agents/task_structrue_reasoner.py,sha256=NQ0V9uY4UelRH5Glw3PwS9HiN4I74A9FxNPcMC5P0lg,3792
20
+ jupyter_agent/bot_agents/task_structrue_summarier.py,sha256=bMrNlb_Xrs4FNosuTBPmMmmHIoPyCIjSUVR_0j7aZZ8,3898
21
+ jupyter_agent/bot_agents/task_summarier.py,sha256=85pW9mSqI-9nfuKr2n-h36OpD3QLA0WPJ1T7eWyww-A,1747
22
+ jupyter_agent/bot_agents/task_verifier.py,sha256=z45jo38c9U4FnS87-AnI4PGki14uuCRhyWVPtAbkl70,2478
23
+ jupyter_agent/bot_agents/task_verify_summarier.py,sha256=usW7RDE8-XAZXAgyHkWU1ZmY-kwi-_ePVXBngYFtb_M,4899
24
+ jupyter_agent/bot_evaluators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
+ jupyter_agent/bot_evaluators/base.py,sha256=yMmeFCNrQRhO9Y4s1OeRAXgxD_m-20a14hM1XFvmN-I,1374
26
+ jupyter_agent/bot_evaluators/dummy_flow.py,sha256=W0BWJKMgXIilZY0i8eP_SNVgqTUd1CT_uqMBs5aygVA,473
27
+ jupyter_agent/bot_evaluators/dummy_global.py,sha256=yZ8fo2xfVN8gZTpBfs8EJ4dcv2t4ls6aXxn3Mo7bNSk,483
28
+ jupyter_agent/bot_evaluators/dummy_task.py,sha256=owh6g6ItPXXYjesplzNMxVcKAU_kktWtuJhqRzZ05V4,475
29
+ jupyter_agent/bot_evaluators/flow_global_planning.py,sha256=kOLd0dCoqrMi6zbe5chXrwxmdahtt8QqX3UnAZgk3AQ,2419
30
+ jupyter_agent/bot_evaluators/flow_task_executor.py,sha256=gzHlKkP9K5fICYgUY5BKAzjwqn3xScxklohqoUCJaZk,4450
31
+ jupyter_agent/bot_flows/__init__.py,sha256=Xe7EbC6bt04Nc4Yr0e--FVvBJCxkZCZkwYL9oahMBtI,338
32
+ jupyter_agent/bot_flows/base.py,sha256=ADNs_-F4XLvEthRyjjBgGkv4KOOYIJRIdaRgjQXHq_k,14116
33
+ jupyter_agent/bot_flows/master_planner.py,sha256=DAsMLXzrKCZaCNoEuPK3A5yWY_PxIcN3bwzYrlpx0pU,794
34
+ jupyter_agent/bot_flows/task_executor_v3.py,sha256=_K6FOM2ZnMZAa8B_Rt1HXDVB20eCQl4Eew2KyfDPyEU,4685
35
+ jupyter_agent-2025.6.105.dist-info/licenses/LICENSE,sha256=nWMmSIg7OepTIDX_OPP0-T9ImeCBBoog7eJxm5awtcM,1068
36
+ jupyter_agent-2025.6.105.dist-info/METADATA,sha256=QqX2ahmch7Ofn_l8GHRjW5BpA1pvlm9kpOTbc5QpnIM,11699
37
+ jupyter_agent-2025.6.105.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
38
+ jupyter_agent-2025.6.105.dist-info/entry_points.txt,sha256=063AB86wSrC_V-iiEEqxTlR4uz-T7VH_YagIpmKFQC0,63
39
+ jupyter_agent-2025.6.105.dist-info/top_level.txt,sha256=c3USTBZ7DZGuvLKlEW-QfGIx0tzn98iCEn3bpdYnDtE,14
40
+ jupyter_agent-2025.6.105.dist-info/RECORD,,
@@ -1,158 +0,0 @@
1
- """
2
- Copyright (c) 2025 viewstar000
3
-
4
- This software is released under the MIT License.
5
- https://opensource.org/licenses/MIT
6
- """
7
-
8
- from enum import Enum
9
- from pydantic import BaseModel, Field
10
- from IPython.display import Markdown
11
- from .base import BaseChatAgent, AgentOutputFormat, AgentModelType
12
- from ..bot_outputs import _D, _I, _W, _E, _F, _M, _B, _C, _O
13
- from ..bot_outputs import ReplyType
14
-
15
-
16
- TASK_PLANNER_PROMPT = """\
17
- **角色定义**:
18
-
19
- 你是一名任务调度专家,负责根据全局分析规划,逐步推进并协调各子任务的执行。
20
-
21
- **任务要求**:
22
-
23
- - 审查全局目标与已完成的子任务结果,判断是否已实现整体目标:
24
- - 若目标已达成,终止流程并输出最终结果。
25
- - 若目标未达成,请根据目标规划说明和已完成子任务,制定下一个**子任务**的执行计划
26
- - 子任务的划分应严格遵守全局目标规划说明的要求
27
- - 协调代码生成Agent、结果验证Agent、结果总结Agent共同完成当前子任务
28
- - 子任务的执行计划具体包括:
29
- 1. 子任务工作描述:
30
- - 简明阐述子任务目标、输入与输出约束
31
- 2. 子任务代码生成Prompt:
32
- - 需生成的代码类型(如数据处理、建模、可视化等)
33
- - 具体输入(数据、变量、参数等)
34
- - 预期输出形式(变量名、图表、文本等)
35
- 3. 子任务结果验证Prompt:
36
- - 检测子任务代码执行结果是否符合当前子任务的要求
37
- - 检测条件只考虑当前子任务的要求,不要考虑全局目标
38
- 4. 子任务结果总结Prompt:
39
- - 说明本子任务结果总结的要点和输出要素,以便后续子任务使用
40
- - 若需要用户提供更多的信息,给出详细的提示信息
41
-
42
- {% include "TASK_OUTPUT_FORMAT" %}
43
-
44
- ---
45
-
46
- {% include "TASK_CONTEXTS" %}
47
-
48
- ---
49
-
50
- {% include "CODE_CONTEXTS" %}
51
-
52
- ---
53
-
54
- {% if task.subject and task.issue %}
55
- **当前子任务信息**:
56
-
57
- ### 当前子任务目标:
58
- {{ task.subject }}
59
-
60
- ### 当前子任务代码:
61
- ```python
62
- {{ task.source }}
63
- ```
64
-
65
- ### 当前子任务输出:
66
- {{ task.output }}
67
-
68
- ### 当前子任务存在的问题:
69
- {{ task.issue }}
70
-
71
- ---
72
-
73
- 请参考上述信息重新规划当前子任务:
74
- {% else %}
75
- 请按要求规划下一个子任务:
76
- {% endif %}
77
-
78
- """
79
-
80
-
81
- class TaskPlannerState(Enum):
82
- PLANNED = "planned" # 任务规划完成
83
- REQUEST_INFO = "request_info" # 需要用户补充更详细的信息
84
- GLOBAL_FINISHED = "global_finished" # 全局目标已达成
85
-
86
-
87
- class TaskPlannerOutput(BaseModel):
88
- state: TaskPlannerState = Field(
89
- description=(
90
- "任务规划状态: "
91
- f"{TaskPlannerState.PLANNED}, 完成规划, 可以开始执行下一步; "
92
- f"{TaskPlannerState.REQUEST_INFO}, 需要用户补充更详细的信息; "
93
- f"{TaskPlannerState.GLOBAL_FINISHED}, 全局目标是否已达成, 无需继续规划; "
94
- ),
95
- examples=[TaskPlannerState.PLANNED.value],
96
- )
97
- subtask_subject: str = Field(
98
- "",
99
- description='子任务简要描述, 在 state="planned" 时必填',
100
- examples=["对...进行...处理,输出..."],
101
- )
102
- subtask_coding_prompt: str = Field(
103
- "",
104
- description='子任务代码生成Prompt, 在 state="planned" 时必填',
105
- examples=["请基于...,计算...,并保存结果为..."],
106
- )
107
- subtask_verify_prompt: str = Field(
108
- "",
109
- description='子任务结果验证Prompt, 在 state="planned" 时必填',
110
- examples=["请验证当前任务结果是否符合以下条件:..."],
111
- )
112
- subtask_summary_prompt: str = Field(
113
- "",
114
- description='子任务结果总结Prompt, 在 state="planned" 时必填',
115
- examples=["请对当前任务的结果进行总结,输出以下要素:..."],
116
- )
117
- request_info_prompt: str = Field(
118
- "",
119
- description='需要用户补充更详细的信息的 Prompt, 在 state="request_info" 时必填',
120
- examples=["请补充与...相关的详细的信息"],
121
- )
122
-
123
-
124
- class TaskPlannerAgentV1(BaseChatAgent):
125
- """任务规划器代理类"""
126
-
127
- PROMPT = TASK_PLANNER_PROMPT
128
- OUTPUT_FORMAT = AgentOutputFormat.JSON
129
- OUTPUT_JSON_SCHEMA = TaskPlannerOutput
130
- MODEL_TYPE = AgentModelType.PLANNER
131
-
132
- def on_reply(self, reply: TaskPlannerOutput):
133
- """执行规划逻辑"""
134
- if reply.state == TaskPlannerState.GLOBAL_FINISHED:
135
- _C(Markdown("全局目标已达成,任务完成!"), reply_type=ReplyType.TASK_RESULT)
136
- return False, reply.state
137
- elif reply.state == TaskPlannerState.REQUEST_INFO:
138
- assert reply.request_info_prompt, "Request info prompt is empty"
139
- _O(Markdown(f"### 需要补充更详细的信息\n\n{reply.request_info_prompt}"), reply_type=ReplyType.TASK_ISSUE)
140
- return True, reply.state
141
- elif reply.state == TaskPlannerState.PLANNED:
142
- assert reply.subtask_subject, "Subtask subject is empty"
143
- assert reply.subtask_coding_prompt, "Subtask coding prompt is empty"
144
- assert reply.subtask_verify_prompt, "Subtask verify prompt is empty"
145
- assert reply.subtask_summary_prompt, "Subtask summary prompt is empty"
146
- _M(
147
- f"### 子任务: {reply.subtask_subject}\n"
148
- f"- Coding: {reply.subtask_coding_prompt}\n"
149
- f"- Verify: {reply.subtask_verify_prompt}\n"
150
- f"- Summary: {reply.subtask_summary_prompt}\n"
151
- )
152
- self.task.set_data("subject", reply.subtask_subject)
153
- self.task.set_data("coding_prompt", reply.subtask_coding_prompt)
154
- self.task.set_data("verify_prompt", reply.subtask_verify_prompt)
155
- self.task.set_data("summary_prompt", reply.subtask_summary_prompt)
156
- return False, reply.state
157
- else:
158
- raise ValueError(f"Unknown task planner state: {reply.state}")