bioguider 0.2.20__py3-none-any.whl → 0.2.22__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.

Potentially problematic release.


This version of bioguider might be problematic. Click here for more details.

Files changed (32) hide show
  1. bioguider/agents/agent_utils.py +16 -10
  2. bioguider/agents/collection_observe_step.py +7 -2
  3. bioguider/agents/collection_task_utils.py +1 -0
  4. bioguider/agents/consistency_collection_step.py +102 -0
  5. bioguider/agents/consistency_evaluation_task.py +57 -0
  6. bioguider/agents/consistency_evaluation_task_utils.py +14 -0
  7. bioguider/agents/consistency_observe_step.py +109 -0
  8. bioguider/agents/consistency_query_step.py +74 -0
  9. bioguider/agents/evaluation_task.py +0 -110
  10. bioguider/agents/evaluation_tutorial_task.py +156 -0
  11. bioguider/agents/evaluation_tutorial_task_prompts.py +114 -0
  12. bioguider/agents/evaluation_userguide_task.py +13 -43
  13. bioguider/agents/prompt_utils.py +15 -2
  14. bioguider/database/code_structure_db.py +20 -9
  15. bioguider/database/summarized_file_db.py +6 -3
  16. bioguider/managers/evaluation_manager.py +16 -2
  17. bioguider/rag/data_pipeline.py +1 -1
  18. bioguider/utils/code_structure_builder.py +15 -8
  19. bioguider/utils/constants.py +12 -12
  20. bioguider/utils/notebook_utils.py +117 -0
  21. bioguider/utils/{file_handler.py → python_file_handler.py} +1 -1
  22. bioguider/utils/r_file_handler.py +549 -0
  23. bioguider/utils/utils.py +34 -1
  24. {bioguider-0.2.20.dist-info → bioguider-0.2.22.dist-info}/METADATA +1 -1
  25. {bioguider-0.2.20.dist-info → bioguider-0.2.22.dist-info}/RECORD +27 -23
  26. bioguider/agents/consistency_collection_execute_step.py +0 -152
  27. bioguider/agents/consistency_collection_observe_step.py +0 -128
  28. bioguider/agents/consistency_collection_plan_step.py +0 -128
  29. bioguider/agents/consistency_collection_task.py +0 -109
  30. bioguider/agents/consistency_collection_task_utils.py +0 -137
  31. {bioguider-0.2.20.dist-info → bioguider-0.2.22.dist-info}/LICENSE +0 -0
  32. {bioguider-0.2.20.dist-info → bioguider-0.2.22.dist-info}/WHEEL +0 -0
bioguider/utils/utils.py CHANGED
@@ -2,6 +2,7 @@ import logging
2
2
  import re
3
3
  import subprocess
4
4
  from typing import Optional
5
+ from pydantic import BaseModel
5
6
  import tiktoken
6
7
 
7
8
  from bioguider.utils.constants import DEFAULT_TOKEN_USAGE
@@ -68,4 +69,36 @@ def increase_token_usage(
68
69
 
69
70
  return token_usage
70
71
 
71
-
72
+ def clean_action_input(action_input: str) -> str:
73
+ replaced_input = ""
74
+
75
+ while (True):
76
+ replaced_input = action_input.strip()
77
+ replaced_input = replaced_input.strip("`")
78
+ replaced_input = replaced_input.strip('"')
79
+ replaced_input = replaced_input.strip()
80
+ replaced_input = replaced_input.strip("`")
81
+ replaced_input = replaced_input.strip('"')
82
+ replaced_input = replaced_input.strip()
83
+ if (replaced_input == action_input):
84
+ break
85
+ action_input = replaced_input
86
+
87
+ action_input = action_input.replace("'", '"')
88
+ action_input = action_input.replace("`", '"')
89
+ return action_input
90
+
91
+ # Convert BaseModel objects to dictionaries for JSON serialization
92
+ def convert_to_serializable(obj):
93
+ if isinstance(obj, BaseModel):
94
+ return obj.model_dump()
95
+ elif hasattr(obj, 'model_dump'):
96
+ return obj.model_dump()
97
+ elif isinstance(obj, dict):
98
+ return {k: convert_to_serializable(v) for k, v in obj.items()}
99
+ elif isinstance(obj, list):
100
+ return [convert_to_serializable(item) for item in obj]
101
+ elif isinstance(obj, tuple):
102
+ return [convert_to_serializable(item) for item in obj]
103
+ else:
104
+ return obj
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: bioguider
3
- Version: 0.2.20
3
+ Version: 0.2.22
4
4
  Summary: An AI-Powered package to help biomedical developers to generate clear documentation
5
5
  License: MIT
6
6
  Author: Cankun Wang
@@ -2,21 +2,21 @@ bioguider/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  bioguider/agents/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  bioguider/agents/agent_task.py,sha256=TL0Zx8zOmiAVslmNbfMPQ38qTQ73QospY6Dwrwf8POg,2890
4
4
  bioguider/agents/agent_tools.py,sha256=r21wHV6a-Ic2T0dk4YzA-_d7PodHPM3GzRxJqv-llSw,7286
5
- bioguider/agents/agent_utils.py,sha256=SoYFc5oZGY2QqTDHR1DCgBPiwQpigUOANHmlUCUPzu4,14683
5
+ bioguider/agents/agent_utils.py,sha256=Mj6yr_2y4veWokXrXlAsaP38Ez9sdnZruM8ZnnpjxQ4,14825
6
6
  bioguider/agents/collection_execute_step.py,sha256=jE_oSQZI5WDaz0bJjUWoAfqWfVbGUqN--cvITSWCGiI,5614
7
- bioguider/agents/collection_observe_step.py,sha256=n863HrbVANQVeltffjS2zXv-AfVErC8ZEMfb_78hafk,5140
7
+ bioguider/agents/collection_observe_step.py,sha256=1xOw6N3uIoyh4h4_vcULAc5x5KZ9G-zZo42AhRidyn8,5373
8
8
  bioguider/agents/collection_plan_step.py,sha256=Nn0f8AOkEDCDtnhaqE7yCQoi7PVpsHmiUcsIqC0T0dQ,5956
9
9
  bioguider/agents/collection_task.py,sha256=MjpTYiQQYUpmQf2UOn-dOCZU3kxypc4uOnzd15wb1Ow,7882
10
- bioguider/agents/collection_task_utils.py,sha256=_e2EebYhl-UYjZ0rHNf2-p32YlstBSffv32suiuT9LI,5386
10
+ bioguider/agents/collection_task_utils.py,sha256=mCmjHFD4HY1mSwkfqPaJbZ8sm6ijjdhnNKj40xudE98,5424
11
11
  bioguider/agents/common_agent.py,sha256=TpfxbYskwuwWrjs1g9RaG7sdA5rOLdiVac7If7uK2sg,4558
12
12
  bioguider/agents/common_agent_2step.py,sha256=rGiDzUkmmUIFnmJJxzXK5M5BfIyINHXLZ0pmPRUVqQg,7911
13
13
  bioguider/agents/common_conversation.py,sha256=_9l6SunRmOZ_3R4Q8CTO9oE_qmP7aYYKFX1EiFBIrm8,2589
14
14
  bioguider/agents/common_step.py,sha256=GdOCbmj1pwh4etg-futVFYVDQuoUG89DnIrw-B6QbzM,2594
15
- bioguider/agents/consistency_collection_execute_step.py,sha256=SBZjdaIc4AX6ljedd8TsJC-1GoYeI16jaqIcfDnTezs,4938
16
- bioguider/agents/consistency_collection_observe_step.py,sha256=XghjlSMBpq1Va68jRP8_-ZG0O7UlZy1Qhwai9c0LNoo,5029
17
- bioguider/agents/consistency_collection_plan_step.py,sha256=NUl0Nl39O5EFibJQQB1oMIVY_Tikh75YNVbyt7ryw6s,5389
18
- bioguider/agents/consistency_collection_task.py,sha256=WP3GL4iPJ38b5F1zZMHmJALx0pRDcF-9JAmz3OHqi6o,5261
19
- bioguider/agents/consistency_collection_task_utils.py,sha256=BnpBXmpxmmr8NRaBw5sACipP0mMtj1Qpe2AvcMlX_cg,6143
15
+ bioguider/agents/consistency_collection_step.py,sha256=evgb0W3PD5pXfViuP_0T5LqLnNxQCuvP14oY0KEtwSc,3424
16
+ bioguider/agents/consistency_evaluation_task.py,sha256=_nYPEs3xhj1jraQWMRML_Y6vZJD_zydY4BstQYXmXJk,1908
17
+ bioguider/agents/consistency_evaluation_task_utils.py,sha256=8PC4KS14ek9NJy3bLuhZNmpOUKFx3_06nKXzuTWb0tE,444
18
+ bioguider/agents/consistency_observe_step.py,sha256=0FEtNpkaGcuL30wb2d43uTlSyHJ9Pxttn9r3NzPD0oo,4409
19
+ bioguider/agents/consistency_query_step.py,sha256=uYE_V_e74kqoDSxmIkMpZpBjoZRKRsJPmiqs1xHhRF8,3674
20
20
  bioguider/agents/dockergeneration_execute_step.py,sha256=F92jDlkc6KjAvTkX7q1FsCYP8J15SCaNgmwh3YPqfDo,6500
21
21
  bioguider/agents/dockergeneration_observe_step.py,sha256=Bo5Td0fzMYLbLki0FvwamzqRFOy4eu3AvIUa8oFApE4,6131
22
22
  bioguider/agents/dockergeneration_plan_step.py,sha256=SB8tQM9PkIKsD2o1DFD7bedcxz6r6hSy8n_EVK60Fz0,7235
@@ -25,21 +25,23 @@ bioguider/agents/dockergeneration_task_utils.py,sha256=v7emqrJlVW-A5ZdLmPSdiaMSK
25
25
  bioguider/agents/evaluation_installation_task.py,sha256=0RNH5NV7YKwn_we_d3IjnFf_ee9IPCEQ_olebq2y8Ng,12130
26
26
  bioguider/agents/evaluation_readme_task.py,sha256=pi3oAGJgZhJgJG1xLgiobrk3Uy2a_JIarD5QSPBkmHA,30647
27
27
  bioguider/agents/evaluation_submission_requirements_task.py,sha256=J_6C-M2AfYue2C-gWBHl7KqGrTBuFBn9zmMV5vSRk-U,7834
28
- bioguider/agents/evaluation_task.py,sha256=c3kvc3xgzGbT0C2KpkE-zHBvaxx9zKdmpLzeKHddrds,12690
28
+ bioguider/agents/evaluation_task.py,sha256=uu0BjalctF9hQjGtT53whbeJHv2RVvs8_2woVUmOLRE,8132
29
+ bioguider/agents/evaluation_tutorial_task.py,sha256=n4eElsGEW38JV7pKtOyoATe1K-pSJZfMr8DdMIAhkyY,8332
30
+ bioguider/agents/evaluation_tutorial_task_prompts.py,sha256=WTqIKBI3JErYaiQfLcPNj_hb3D-hSZrae50uJ7526zw,5996
29
31
  bioguider/agents/evaluation_userguide_prompts.py,sha256=eyJUx5nUr8v9k0B5GpKDaX2dBxSLVZGA0fwOWS4Uiow,7154
30
- bioguider/agents/evaluation_userguide_task.py,sha256=AJ7y5WSMs4EqXpQzyAu_5NPmWK0jl3AeHhRXxdZgpz0,8266
32
+ bioguider/agents/evaluation_userguide_task.py,sha256=ONdempCOyn_N-LGV35diKciBbnjDSItXchcLV738XTw,6456
31
33
  bioguider/agents/identification_execute_step.py,sha256=w3IjL8f2WiHCyiLjVSoySnIAXpi1-hK1DLKCnXbAN2Y,5587
32
34
  bioguider/agents/identification_observe_step.py,sha256=Me5mhEM4e7FGnVFcluNtqfhIxzng6guGIu39xi1TrS8,4341
33
35
  bioguider/agents/identification_plan_step.py,sha256=owsTK1NZIuiZL7QPVknJyp9TBRK-mhnuf2RwK4YzaxU,5442
34
36
  bioguider/agents/identification_task.py,sha256=bTbovxxQVpO1TcdcQAxDxwPISuAcXndO7zsvHpJSb64,10147
35
37
  bioguider/agents/identification_task_utils.py,sha256=Lf0Rj0L0KSiyJmPAgeSz0vLUFQr6TSFuzgufimEN4H0,630
36
38
  bioguider/agents/peo_common_step.py,sha256=iw2c1h7X11WJzSE2tSRg0UAoXH0QOlQDxW9CCzSVMOY,2677
37
- bioguider/agents/prompt_utils.py,sha256=kTeK0LOsxpEIpQ5PMXY0DOHXJ5Z6ryu0UuJIO4ga9Rg,17743
39
+ bioguider/agents/prompt_utils.py,sha256=T7ec7DbdGacIMOE4GAnlzHjuNzbzPDeSVWHvmWt1UGk,19427
38
40
  bioguider/agents/python_ast_repl_tool.py,sha256=o7-4P1h8jS8ikhGSA4CI_OWQ2a0Eg5tEdmuAp_qrO-0,2519
39
41
  bioguider/agents/rag_collection_task.py,sha256=r_jPAMjQcC7dIydKxX77UuMqjJ3MiVKswNZ-yNw7yx8,5199
40
42
  bioguider/conversation.py,sha256=DIvk_d7pz_guuORByK1eaaF09FAK-8shcNTrbSUHz9Y,1779
41
- bioguider/database/code_structure_db.py,sha256=drYkoQa7mDexCpulG3885Gwcnu92lnHNRlWT8byjF-A,16630
42
- bioguider/database/summarized_file_db.py,sha256=gGubM5vH3SN_1vouKO0LemvE_EfyjinAScRhlvxJsi0,4654
43
+ bioguider/database/code_structure_db.py,sha256=q9tGZLWrjPi7a3u1b2iUnMO30lNWKbeMOkpDRffev2M,16973
44
+ bioguider/database/summarized_file_db.py,sha256=U60c62e2Bx7PwsTAcCQgljNxD5u5awjpj5qpHEgJbac,4801
43
45
  bioguider/generation/__init__.py,sha256=esV02QgCsY67-HBwSHDbA5AcbKzNRIT3wDwwh6N4OFM,945
44
46
  bioguider/generation/change_planner.py,sha256=1u_1tcVwggVw6QebXvPJVULYnRAIkKMteFxbnf42aAw,6964
45
47
  bioguider/generation/document_renderer.py,sha256=67-XGFGNe8WgHJpqkHLMecgk2OeV8a5cJRAeDTLsXG4,1806
@@ -53,24 +55,26 @@ bioguider/generation/report_loader.py,sha256=KtJ6JHGPDL-PQoucU8hkVzMSz-B0bHbF2WS
53
55
  bioguider/generation/style_analyzer.py,sha256=Vn9FAK1qJBNLolLC1tz362k4UBaPl107BlvkQc8pV2I,983
54
56
  bioguider/generation/suggestion_extractor.py,sha256=tfkyWtdbAo-maLCF_wqwBXyh93yjulvDY17FuvTnTjk,7611
55
57
  bioguider/generation/test_metrics.py,sha256=fG6H1jVikHEx1YvN5Ds4QbVinudJ5OEYkzrV760oLLQ,3766
56
- bioguider/managers/evaluation_manager.py,sha256=obsesQdEgxBzTd1Re00kanH1d5_4_vxzXI_ndICgedg,5834
58
+ bioguider/managers/evaluation_manager.py,sha256=2RRlVWu3kxBYrK0DRsX1k82LLFKJaNZ1i4HuCYxwJPw,6447
57
59
  bioguider/managers/generation_manager.py,sha256=EbAJSvUz-SIriVlozuJ6wa5_1aIbbFfpgg3c9Vcz34g,7615
58
60
  bioguider/managers/generation_test_manager.py,sha256=0ty8IibdfN90Oj6M6lkYbxASnQxHYb9I3w9eG7hvEsQ,3270
59
61
  bioguider/rag/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
60
62
  bioguider/rag/config.py,sha256=5g4IqTzgyfZfax9Af9CTkXShgItPOt4_9TEMSekCPik,4602
61
- bioguider/rag/data_pipeline.py,sha256=bkJ2IUCgPx_OL2uZtPd6cIBor2VFZEIfGd5kVlmiPjw,27292
63
+ bioguider/rag/data_pipeline.py,sha256=hyBmjOpP1ka_y_4X0lUwlNKEBjmPNOmETEfQf-s86ZY,27316
62
64
  bioguider/rag/embedder.py,sha256=jofR8hOj3Aj2IyBQ9y6FeAc84tgq5agbIfCGyFxYpJ8,650
63
65
  bioguider/rag/rag.py,sha256=JFPwrJlKDSyd3U3Gce_NSxI5343eNUbqPG9Fs5Pfoq0,4696
64
66
  bioguider/settings.py,sha256=BD_iz9aYarxmWUl0XaKl4-D4oTXMhFzljsXLNn2phis,3143
65
- bioguider/utils/code_structure_builder.py,sha256=TBrsmlUPEwqpi5bSVLrOEwFK1dQ49goYJ1EGYmRrtZ8,1607
66
- bioguider/utils/constants.py,sha256=Yzo9oFG4P4C83vKl22RsWkIDa4dcitvcCIceusNPIRQ,8928
67
+ bioguider/utils/code_structure_builder.py,sha256=PVeooVKxkiBEkX_VEu8h1ACGs-ynrgk_ce2FKJfeeZc,1947
68
+ bioguider/utils/constants.py,sha256=NGmqEgxNDL1fe-htJbtHGcU94EVUK28YAupxGYOJO_c,9012
67
69
  bioguider/utils/default.gitignore,sha256=XjPdyO2KV8z8iyuqluaNR_70tBQftMpyKL8HboVNyeI,1605
68
- bioguider/utils/file_handler.py,sha256=xTrJBQ7VY5baIJPpX7YJP0oniPO3y9ltzayqUOQXJ5g,2644
69
70
  bioguider/utils/file_utils.py,sha256=9VfAHsz1UkFPtzAmvWZvPl1TMaKIYNjNlLgsfB8tNjg,3683
70
71
  bioguider/utils/gitignore_checker.py,sha256=pOYUwsS9D5014LxcZb0cj3s2CAYaD2uF_pYJpaNKcho,6532
72
+ bioguider/utils/notebook_utils.py,sha256=SfU1iLuwgbDzNN-TUh_qbnfUSgn-PI6NrK6QfmdpMqQ,4009
71
73
  bioguider/utils/pyphen_utils.py,sha256=cdZc3qphkvMDeL5NiZ8Xou13M_uVNP7ifJ-FwxO-0BE,2680
72
- bioguider/utils/utils.py,sha256=aWtgdvB04gEiJTfQNK4aQPO1mxv2zRZTbDaGUBy9DFc,2275
73
- bioguider-0.2.20.dist-info/LICENSE,sha256=qzkvZcKwwA5DuSuhXMOm2LcO6BdEr4V7jwFZVL2-jL4,1065
74
- bioguider-0.2.20.dist-info/METADATA,sha256=jAGUMMHuLYW5_lyvc0tYcvKGYlB9YUG1hqT3Kjaqii0,1868
75
- bioguider-0.2.20.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
76
- bioguider-0.2.20.dist-info/RECORD,,
74
+ bioguider/utils/python_file_handler.py,sha256=BERiE2RHxpu3gAzv26jr8ZQetkrtnMZOv9SjpQ7WIdg,2650
75
+ bioguider/utils/r_file_handler.py,sha256=8HpFaYKP8N1nItwr9tOx49m99pcLSt8EUtTNTJ7xNoE,19564
76
+ bioguider/utils/utils.py,sha256=1N7Wv_i9spTBQ_FbZnlxsjC8mszbBzaegrmvuKGUISg,3531
77
+ bioguider-0.2.22.dist-info/LICENSE,sha256=qzkvZcKwwA5DuSuhXMOm2LcO6BdEr4V7jwFZVL2-jL4,1065
78
+ bioguider-0.2.22.dist-info/METADATA,sha256=khsXgvUKBtkO4HOo1dCqVsw8vgk7zwOh9KdZFP4DtSc,1868
79
+ bioguider-0.2.22.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
80
+ bioguider-0.2.22.dist-info/RECORD,,
@@ -1,152 +0,0 @@
1
- import logging
2
-
3
- from langchain_openai.chat_models.base import BaseChatOpenAI
4
- from langchain.tools import BaseTool, StructuredTool
5
- from langchain.agents import AgentExecutor, create_react_agent
6
- from langchain_community.callbacks.openai_info import OpenAICallbackHandler
7
-
8
- from bioguider.agents.consistency_collection_task_utils import ConsistencyCollectionWorkflowState
9
- from bioguider.agents.consistency_collection_task_utils import ConsistencyCollectionWorkflowState
10
- from bioguider.database.code_structure_db import CodeStructureDb
11
- from bioguider.utils.constants import DEFAULT_TOKEN_USAGE
12
- from bioguider.agents.agent_utils import CustomOutputParser, CustomPromptTemplate
13
- from bioguider.agents.peo_common_step import (
14
- PEOCommonStep,
15
- )
16
-
17
- logger = logging.getLogger(__name__)
18
-
19
- CONSISTENCY_EVAL_EXECUTION_SYSTEM_PROMPT = """You are an expert developer specializing in the biomedical domain.
20
-
21
- You are given a **plan** and are expected to complete it using the available tools.
22
-
23
- ---
24
-
25
- ### **Available Tools**
26
- {tools}
27
-
28
- ---
29
-
30
- ### **Your Task**
31
-
32
- Your job is to **execute the given plan step by step**, using the tools available to you.
33
-
34
- ---
35
-
36
- ### **Output Format (Strict Order Required)**
37
-
38
- For **each step**, follow the **exact format** below and **do not change the order of the fields** under any circumstances:
39
-
40
- ```
41
- Thought: Describe what you are thinking or planning to do next.
42
- Action: The tool you are going to use (must be one of: {tool_names})
43
- Action Input: The input provided to the selected action
44
- Observation: The result returned by the action
45
- ```
46
-
47
- ---
48
-
49
- ### **Important Instructions**
50
- 1. You may repeat the **Thought → Action → Action Input → Observation** loop as needed.
51
- 2. Once all steps in the plan have been executed, output all the results using this format:
52
- 3. For each step, **only execute one tool**.
53
-
54
- ```
55
- Thought: I have completed the plan.
56
- Final Answer:
57
- Action: <tool_name>
58
- Action Input: <input>
59
- Action Observation: <Observation1>
60
- ---
61
- Action: <tool_name>
62
- Action Input: <input>
63
- Action Observation: <Observation2>
64
- ---
65
- ...
66
- ```
67
-
68
- ---
69
-
70
- ### **Plan**
71
- {plan_actions}
72
-
73
- ### **Actions Already Taken**
74
- {agent_scratchpad}
75
-
76
- ---
77
-
78
- {input}
79
- """
80
-
81
- class ConsistencyCollectionExecuteStep(PEOCommonStep):
82
- def __init__(
83
- self,
84
- llm: BaseChatOpenAI,
85
- code_structure_db: CodeStructureDb,
86
- custom_tools: list[BaseTool] | None = None,
87
- ):
88
- self.llm = llm
89
- self.code_structure_db = code_structure_db
90
- self.step_name = "Consistency Collection Execute Step"
91
- self.custom_tools = custom_tools if custom_tools is not None else []
92
-
93
- def _execute_directly(self, state: ConsistencyCollectionWorkflowState):
94
- plan_actions = state["plan_actions"]
95
- prompt = CustomPromptTemplate(
96
- template=CONSISTENCY_EVAL_EXECUTION_SYSTEM_PROMPT,
97
- tools=self.custom_tools,
98
- plan_actions=plan_actions,
99
- input_variables=[
100
- "tools", "tool_names", "agent_scratchpad",
101
- "intermediate_steps", "plan_actions",
102
- ],
103
- )
104
- output_parser = CustomOutputParser()
105
- agent = create_react_agent(
106
- llm=self.llm,
107
- tools=self.custom_tools,
108
- prompt=prompt,
109
- output_parser=output_parser,
110
- stop_sequence=["\nObservation:"],
111
- )
112
- callback_handler = OpenAICallbackHandler()
113
- agent_executor = AgentExecutor(
114
- agent=agent,
115
- tools=self.custom_tools,
116
- max_iterations=30,
117
- )
118
- response = agent_executor.invoke(
119
- input={
120
- "plan_actions": plan_actions,
121
- "input": "Now, let's begin."
122
- },
123
- config={
124
- "callbacks": [callback_handler],
125
- "recursion_limit": 20,
126
- },
127
- )
128
- if "output" in response:
129
- output = response["output"]
130
- self._print_step(state, step_output=f"**Execute Output:** \n{output}")
131
- if "**Final Answer**" in output:
132
- final_answer = output.split("**Final Answer:**")[-1].strip().strip(":")
133
- step_output = final_answer
134
- elif "Final Answer" in output:
135
- final_answer = output.split("Final Answer")[-1].strip().strip(":")
136
- step_output = final_answer
137
- else:
138
- step_output = output
139
- self._print_step(state, step_output=step_output)
140
- state["step_output"] = step_output
141
- else:
142
- logger.error("No output found in the response.")
143
- self._print_step(
144
- state,
145
- step_output="Error: No output found in the response.",
146
- )
147
- state["step_output"] = "Error: No output found in the response."
148
-
149
- token_usage = vars(callback_handler)
150
- token_usage = {**DEFAULT_TOKEN_USAGE, **token_usage}
151
-
152
- return state, token_usage
@@ -1,128 +0,0 @@
1
- from typing import Callable
2
-
3
- from langchain_openai.chat_models.base import BaseChatOpenAI
4
- from langchain_core.prompts import ChatPromptTemplate
5
- from bioguider.agents.agent_utils import ObservationResult
6
- from bioguider.agents.common_agent_2step import CommonAgentTwoSteps
7
- from bioguider.agents.consistency_collection_task_utils import ConsistencyCollectionWorkflowState
8
- from bioguider.agents.peo_common_step import PEOCommonStep
9
-
10
- CONSISTENCY_EVAL_OBSERVE_SYSTEM_PROMPT = """You are an expert developer specializing in the biomedical domain.
11
-
12
- ### **Goal**
13
- Your task is to collect the function, class, and method definitions and docstrings for a given user guide/API documentation.
14
-
15
- ---
16
-
17
- ### **Intermediate Steps**
18
- Here are the results from previous steps:
19
- {intermediate_steps}
20
-
21
- ---
22
-
23
- ### **Instructions**
24
- 1. Your goal is if you have enough information to evaluate the consistency of the user guide/API documentation.
25
- 2. Carefully review the **Goal**, **User Guide/API Documentation**, and **Intermediate Output**.
26
- 3. If you believe you have enough information to evaluate the consistency of the user guide/API documentation:
27
-
28
- * Proceed with the following format:
29
-
30
- * Provide your reasoning under **Analysis**
31
- * Then give your final answer under **FinalAnswer**
32
- * **FinalAnswer** format must exactly match this format:
33
- **FinalAnswer**: {{"final_answer": "yes" or "no"}}
34
- * Your answer **must exactly match the follwing format** (note: no JSON code block, no additional comments), **do not** make up anything:
35
-
36
- ```
37
- **Analysis**: your analysis here
38
- **FinalAnswer**: {{"final_answer": "yes" or "no"}}
39
- ```
40
- 4. If you believe you do not have enough information to evaluate the consistency of the user guide/API documentation:
41
-
42
- * Provide your reasoning under **Thoughts**:
43
-
44
- ```
45
- **Thoughts**: your thoughts here
46
- ```
47
-
48
- Be precise and support your reasoning with evidence from the input.
49
-
50
- ---
51
-
52
- ### **Notes**
53
- We are collecting information over multiple rounds, your thoughts and the output of this step will be persisted, so please **do not rush to provide a Final Answer**.
54
- If you find the current information insufficient, share your reasoning or thoughts instead—we’ll continue with the next round accordingly.
55
-
56
- ---
57
-
58
- ### **Input User Guide/API Documentation**
59
- {user_guide_api_documentation}
60
-
61
- ---
62
-
63
- """
64
-
65
-
66
- class ConsistencyCollectionObserveStep(PEOCommonStep):
67
- def __init__(
68
- self,
69
- llm: BaseChatOpenAI,
70
- ):
71
- super().__init__(llm=llm)
72
- self.step_name = "Consistency Collection Observe Step"
73
-
74
- def _build_prompt(self, state):
75
- user_guide_api_documentation = state["user_guide_api_documentation"]
76
- intermediate_steps = self._build_intermediate_steps(state)
77
- prompt = ChatPromptTemplate.from_template(CONSISTENCY_EVAL_OBSERVE_SYSTEM_PROMPT)
78
- return prompt.format(
79
- user_guide_api_documentation=user_guide_api_documentation,
80
- intermediate_steps=intermediate_steps,
81
- )
82
-
83
- def _collect_final_answer(self, state: ConsistencyCollectionWorkflowState):
84
- if not ("final_answer" in state and state["final_answer"] is not None and
85
- state["final_answer"].strip().lower() == "yes"):
86
- return None
87
-
88
- final_result = ""
89
- if "intermediate_steps" in state and state["intermediate_steps"] is not None:
90
- for i in range(len(state["intermediate_steps"])):
91
- final_result += state["intermediate_steps"][i]
92
- final_result += "\n\n"
93
- if "step_output" in state and state["step_output"] is not None:
94
- final_result += state["step_output"]
95
- final_result += "\n\n"
96
-
97
- return final_result
98
-
99
-
100
- def _execute_directly(self, state: ConsistencyCollectionWorkflowState):
101
- system_prompt = self._build_prompt(state)
102
- agent = CommonAgentTwoSteps(llm=self.llm)
103
- res, _, token_usage, reasoning_process = agent.go(
104
- system_prompt=system_prompt,
105
- instruction_prompt="Now, let's begin the consistency collection observe step.",
106
- schema=ObservationResult,
107
- )
108
- state["final_answer"] = res.FinalAnswer
109
- analysis = res.Analysis
110
- thoughts = res.Thoughts
111
- state["step_analysis"] = analysis
112
- state["step_thoughts"] = thoughts
113
- state["step_count"] += 1
114
- state["final_assembly_result"] = self._collect_final_answer(state)
115
- self._print_step(
116
- state,
117
- step_output=f"**Observation Reasoning Process {state['step_count']}**\n{reasoning_process}"
118
- )
119
- self._print_step(
120
- state,
121
- step_output=f"Final Answer: {res.FinalAnswer if res.FinalAnswer else None}\nAnalysis: {analysis}\nThoughts: {thoughts}",
122
- )
123
- if state["final_assembly_result"] is not None:
124
- self._print_step(
125
- state,
126
- step_output=f"Final Assembly Result: {state['final_assembly_result']}",
127
- )
128
- return state, token_usage
@@ -1,128 +0,0 @@
1
- from langchain_openai.chat_models.base import BaseChatOpenAI
2
-
3
- from langchain.tools import BaseTool
4
- from langchain_core.prompts import ChatPromptTemplate, StringPromptTemplate
5
- from bioguider.agents.agent_utils import (
6
- convert_plan_to_string,
7
- get_tool_names_and_descriptions,
8
- PlanAgentResultJsonSchema,
9
- PlanAgentResult,
10
- )
11
- from bioguider.agents.common_agent_2step import CommonAgentTwoChainSteps, CommonAgentTwoSteps
12
- from bioguider.agents.consistency_collection_task_utils import ConsistencyCollectionWorkflowState
13
- from bioguider.agents.peo_common_step import PEOCommonStep
14
-
15
- CONSISTANCE_EVAL_PLAN_SYSTEM_PROMPT = ChatPromptTemplate.from_template("""### **Goal**
16
- You are an expert developer specializing in the biomedical domain.
17
- Your task is to collect the function, class, and method definitions and docstrings for a given user guide/API documentation.
18
-
19
- ---
20
-
21
- ### **Function Tools**
22
- You have access to the following function tools:
23
- {tools}
24
-
25
- ---
26
-
27
- ### **Intermediate Steps**
28
- Here are the results from previous steps:
29
- {intermediate_steps}
30
-
31
- ---
32
-
33
- ### **Intermediate Thoughts**
34
- - **Analysis**: {intermediate_analysis}
35
- - **Thoughts**: {intermediate_thoughts}
36
-
37
- ---
38
-
39
- ### **Instructions**
40
- 1. We will iterate through multiple **Plan -> Execution -> Observation** loops as needed.
41
- - All variables and tool outputs are **persisted across rounds**, so you can build on prior results.
42
- - Develop your plan **incrementally**, and reflect on intermediate observations before proceeding.
43
- - Limit each step to **one or two actions** — avoid trying to complete everything in a single step.
44
-
45
- 2. Your task is to evaluate the consistency of the user guide/API documentation.
46
-
47
- 3. You may use
48
- - the `retrieve_function_definition_and_docstring` tool to get the function definition and docstring or,
49
- - the `retrieve_class_definition_and_docstring` to get the class definition and docstring or,
50
- - the `retrieve_class_and_method_definition_and_docstring` to get the class and method definition and docstring.
51
-
52
- 4. Your plan can only use the above tools, **do not** make up any tools not in the above tools list.
53
-
54
- 5. If no function, class, or method is found in the given user guide/API documentation, you should return "N/A" as an empty plan.
55
- Our tools can only retrieve the **function**, **class**, **method** definition and docstring, **do not** make up any function, class, or method name.
56
-
57
-
58
- ### **Input User Guide/API Documentation**
59
- {user_guide_api_documentation}
60
-
61
- ### **Output Format**
62
- Your plan **must exactly match** a sequence of steps in the following format, **do not** make up anything:
63
-
64
- Step: <tool name> # Tool name **must be one** of {tool_names}
65
- Step Input: <function/class/method name>
66
- Step Input: <file path, if not sure, just put "N/A">
67
-
68
- Step: <tool name> # Tool name **must be one** of {tool_names}
69
- Step Input: <function/class/method name>
70
- Step Input: <file path, if not sure, just put "N/A">
71
- ...
72
-
73
- ...
74
- """)
75
-
76
- class ConsistencyCollectionPlanStep(PEOCommonStep):
77
- """
78
- ConsistencyCollectionPlanStep is a step in the consistency collection plan process.
79
- It is responsible for initializing the tools and compiling the step.
80
- """
81
-
82
- def __init__(
83
- self,
84
- llm: BaseChatOpenAI,
85
- custom_tools: list[BaseTool] | None = None,
86
- ):
87
- super().__init__(llm)
88
- self.step_name = "Consistency Collection Plan Step"
89
- self.custom_tools = custom_tools if custom_tools is not None else []
90
-
91
- def _prepare_system_prompt(self, state: ConsistencyCollectionWorkflowState) -> str:
92
- user_guide_api_documentation = state["user_guide_api_documentation"]
93
- intermediate_steps = self._build_intermediate_steps(state)
94
- step_analysis, step_thoughts = self._build_intermediate_analysis_and_thoughts(state)
95
- tool_names, tools_desc = get_tool_names_and_descriptions(self.custom_tools)
96
- system_prompt = CONSISTANCE_EVAL_PLAN_SYSTEM_PROMPT.format(
97
- tools=tools_desc,
98
- intermediate_steps=intermediate_steps,
99
- intermediate_analysis=step_analysis,
100
- intermediate_thoughts=step_thoughts,
101
- tool_names=tool_names,
102
- user_guide_api_documentation=user_guide_api_documentation,
103
- )
104
- self._print_step(
105
- state,
106
- step_output="**Intermediate Step Output**\n" + intermediate_steps
107
- )
108
- self._print_step(
109
- state,
110
- step_output="**Intermediate Step Analysis**\n{step_analysis}\n**Intermediate Step Thoughts**\n{step_thoughts}",
111
- )
112
- return system_prompt
113
-
114
- def _execute_directly(self, state: ConsistencyCollectionWorkflowState):
115
- system_prompt = self._prepare_system_prompt(state)
116
- agent = CommonAgentTwoSteps(llm=self.llm)
117
- res, _, token_usage, reasoning_process = agent.go(
118
- system_prompt=system_prompt,
119
- instruction_prompt="Now, let's begin the consistency collection plan step.",
120
- schema=PlanAgentResultJsonSchema,
121
- )
122
- PEOCommonStep._reset_step_state(state)
123
- res = PlanAgentResult(**res)
124
- self._print_step(state, step_output=f"**Reasoning Process**\n{reasoning_process}")
125
- self._print_step(state, step_output=f"**Plan**\n{str(res.actions)}")
126
- state["plan_actions"] = convert_plan_to_string(res)
127
-
128
- return state, token_usage
@@ -1,109 +0,0 @@
1
- import os
2
- from typing import Callable, Optional, TypedDict
3
- from langchain.prompts import ChatPromptTemplate
4
- from langchain_openai.chat_models.base import BaseChatOpenAI
5
- from langchain_core.messages import AIMessage
6
- from langchain.tools import StructuredTool
7
- from pydantic import BaseModel, Field
8
- import logging
9
- from langgraph.graph import StateGraph, START, END
10
-
11
- from bioguider.agents.agent_task import AgentTask
12
- from bioguider.agents.agent_tools import agent_tool
13
- from bioguider.agents.agent_utils import read_file, summarize_file
14
- from bioguider.agents.peo_common_step import PEOWorkflowState
15
- from bioguider.agents.common_agent import CommonAgent
16
- from bioguider.agents.common_agent_2step import CommonAgentTwoSteps
17
- from bioguider.agents.consistency_collection_task_utils import (
18
- ConsistencyCollectionWorkflowState,
19
- retrieve_function_definition_and_docstring_tool,
20
- retrieve_class_definition_and_docstring_tool,
21
- retrieve_class_and_method_definition_and_docstring_tool,
22
- retrieve_method_definition_and_docstring_tool,
23
- )
24
- from bioguider.agents.consistency_collection_plan_step import ConsistencyCollectionPlanStep
25
- from bioguider.agents.consistency_collection_observe_step import ConsistencyCollectionObserveStep
26
- from bioguider.agents.consistency_collection_execute_step import ConsistencyCollectionExecuteStep
27
- from bioguider.database.code_structure_db import CodeStructureDb
28
-
29
- logger = logging.getLogger(__name__)
30
-
31
- class ConsistencyCollectionTask(AgentTask):
32
- def __init__(
33
- self,
34
- llm: BaseChatOpenAI,
35
- code_structure_db: CodeStructureDb,
36
- step_callback: Callable | None = None,
37
- ):
38
- super().__init__(llm=llm, step_callback=step_callback)
39
- self.llm = llm
40
- self.code_structure_db = code_structure_db
41
-
42
- func_tool = retrieve_function_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
43
- class_tool = retrieve_class_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
44
- class_and_method_tool = retrieve_class_and_method_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
45
- method_tool = retrieve_method_definition_and_docstring_tool(llm=llm, code_structure_db=code_structure_db)
46
- self.tools = [func_tool, class_tool, class_and_method_tool, method_tool]
47
- self.custom_tools = [
48
- StructuredTool.from_function(
49
- func_tool.run,
50
- description=func_tool.__class__.__doc__,
51
- name=func_tool.__class__.__name__,
52
- ),
53
- StructuredTool.from_function(
54
- class_tool.run,
55
- description=class_tool.__class__.__doc__,
56
- name=class_tool.__class__.__name__,
57
- ),
58
- StructuredTool.from_function(
59
- class_and_method_tool.run,
60
- description=class_and_method_tool.__class__.__doc__,
61
- name=class_and_method_tool.__class__.__name__,
62
- ),
63
- StructuredTool.from_function(
64
- method_tool.run,
65
- description=method_tool.__class__.__doc__,
66
- name=method_tool.__class__.__name__,
67
- ),
68
- ]
69
-
70
- self.steps = [
71
- ConsistencyCollectionPlanStep(llm=llm, custom_tools=self.custom_tools),
72
- ConsistencyCollectionExecuteStep(llm=llm, code_structure_db=code_structure_db, custom_tools=self.custom_tools),
73
- ConsistencyCollectionObserveStep(llm=llm)
74
- ]
75
-
76
- def _compile(self, repo_path: str, gitignore_path: str):
77
- def check_observe_step(state: ConsistencyCollectionWorkflowState):
78
- if "final_answer" in state and state["final_answer"] is not None:
79
- return END
80
- return "plan_step"
81
- def check_plan_step(state: ConsistencyCollectionWorkflowState):
82
- if "plan_actions" in state and state["plan_actions"] is not None and len(state["plan_actions"]) > 0:
83
- return "execute_step"
84
- return END
85
-
86
- graph = StateGraph(ConsistencyCollectionWorkflowState)
87
- graph.add_node("plan_step", self.steps[0].execute)
88
- graph.add_node("execute_step", self.steps[1].execute)
89
- graph.add_node("observe_step", self.steps[2].execute)
90
- graph.add_edge(START, "plan_step")
91
- graph.add_conditional_edges("plan_step", check_plan_step, {"execute_step", END})
92
- graph.add_edge("execute_step", "observe_step")
93
- graph.add_conditional_edges("observe_step", check_observe_step, {"plan_step", END})
94
-
95
- self.graph = graph.compile()
96
-
97
- def collect(self, user_guide_api_documentation: str) -> tuple[bool, str | None]:
98
- s = self._go_graph({
99
- "user_guide_api_documentation": user_guide_api_documentation,
100
- "step_count": 0,
101
- })
102
- # analyze the final assembly result
103
- if "final_assembly_result" in s and s["final_assembly_result"] is not None:
104
- self._print_step(step_name="Final Assembly Result")
105
- self._print_step(step_output=s["final_assembly_result"])
106
- return True, s["final_assembly_result"]
107
- else:
108
- return False, s["thoughts"] if "thoughts" in s else None
109
-