@brandon_9527/tcode 1.0.2 ā 1.0.3
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.
- package/dist/python-src/.autodev/skills/teams/scripts/README.md +29 -0
- package/dist/python-src/.autodev/skills/teams/scripts/cursor_dispatch.sh +88 -0
- package/dist/python-src/.autodev/skills/teams/scripts/dispatch.sh +112 -0
- package/dist/python-src/.autodev/skills/teams/scripts/label.sh +62 -0
- package/dist/python-src/.autodev/skills/teams/scripts/layout.sh +181 -0
- package/dist/python-src/.autodev/skills/teams/scripts/old_dispatch.sh +42 -0
- package/dist/python-src/.autodev/skills/teams/scripts/pipe.sh +19 -0
- package/dist/python-src/.autodev/skills/teams/scripts/pipe_dispatch.sh +59 -0
- package/dist/python-src/.autodev/skills/teams/scripts/run.sh +18 -0
- package/dist/python-src/.autodev/skills/teams/scripts/stop.sh +26 -0
- package/dist/python-src/.autodev/skills/teams/scripts/tmux-layout.sh +43 -0
- package/dist/python-src/entry.py +28 -1
- package/dist/python-src/main.py +382 -3
- package/dist/python-src/pyproject.toml +1 -1
- package/dist/python-src/src/ai_tcode.egg-info/PKG-INFO +30 -0
- package/dist/python-src/src/ai_tcode.egg-info/SOURCES.txt +48 -0
- package/dist/python-src/src/ai_tcode.egg-info/dependency_links.txt +1 -0
- package/dist/python-src/src/ai_tcode.egg-info/requires.txt +26 -0
- package/dist/python-src/src/ai_tcode.egg-info/top_level.txt +9 -0
- package/dist/python-src/src/managers/manager_agent.py +200 -0
- package/dist/python-src/src/managers/manager_context.py +49 -0
- package/dist/python-src/src/managers/manager_instruction.py +192 -0
- package/dist/python-src/src/managers/sandbox.py +3 -3
- package/dist/python-src/src/middlewares/dynamic_content.py +63 -0
- package/dist/python-src/src/middlewares/hitl.py +3 -3
- package/dist/python-src/src/middlewares/memory.py +44 -0
- package/dist/python-src/src/middlewares/subagents.py +25 -25
- package/dist/python-src/src/middlewares/summary.py +35 -35
- package/dist/python-src/src/middlewares/utils.py +5 -0
- package/dist/python-src/src/prompts/prompts.py +1 -0
- package/dist/python-src/src/stream/formatter.py +17 -17
- package/dist/python-src/src/stream/handler.py +109 -81
- package/dist/python-src/src/stream/handler_with_tracker.py +10 -10
- package/dist/python-src/src/tools/web.py +10 -9
- package/dist/python-src/src/tui/chatui.py +67 -51
- package/dist/python-src/src/tui/components/tlist.py +6 -6
- package/dist/python-src/src/tui/components/tscroll_panel.py +8 -8
- package/dist/python-src/src/tui/utils/trender.py +27 -27
- package/dist/python-src/src/utils/prompt.py +15 -4
- package/dist/python-src/uv.lock +1980 -2094
- package/package.json +1 -1
- package/dist/python-src/src/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/managers/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/managers/__pycache__/sandbox.cpython-311.pyc +0 -0
- package/dist/python-src/src/middlewares/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/middlewares/__pycache__/hitl.cpython-311.pyc +0 -0
- package/dist/python-src/src/middlewares/dynamic_prompt.py +0 -15
- package/dist/python-src/src/stream/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/stream/__pycache__/emitter.cpython-311.pyc +0 -0
- package/dist/python-src/src/stream/__pycache__/file_write_parser.cpython-311.pyc +0 -0
- package/dist/python-src/src/stream/__pycache__/formatter.cpython-311.pyc +0 -0
- package/dist/python-src/src/stream/__pycache__/handler.cpython-311.pyc +0 -0
- package/dist/python-src/src/stream/__pycache__/tracker.cpython-311.pyc +0 -0
- package/dist/python-src/src/stream/__pycache__/utils.cpython-311.pyc +0 -0
- package/dist/python-src/src/tools/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/tools/__pycache__/skill_loader.cpython-311.pyc +0 -0
- package/dist/python-src/src/tools/__pycache__/tools.cpython-311.pyc +0 -0
- package/dist/python-src/src/tools/__pycache__/web.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/__pycache__/chatui.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/__pycache__/config.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/components/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/components/__pycache__/live_spinner.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/components/__pycache__/tdiff.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/components/__pycache__/tdisplay.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/components/__pycache__/tlist.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/components/__pycache__/tscroll_panel.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/utils/__pycache__/render.cpython-311.pyc +0 -0
- package/dist/python-src/src/tui/utils/__pycache__/trender.cpython-311.pyc +0 -0
- package/dist/python-src/src/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- package/dist/python-src/src/utils/__pycache__/utils.cpython-311.pyc +0 -0
|
@@ -59,17 +59,17 @@ async def astream_handler(stream,emitter,tracker,debug=False):
|
|
|
59
59
|
else:A=B
|
|
60
60
|
if F:Y=type(A).__name__;print(f"[DEBUG] Event: {Y}")
|
|
61
61
|
if isinstance(A,(AIMessageChunk,AIMessage)):
|
|
62
|
-
for C in
|
|
62
|
+
for C in bn(A,E,J,S):
|
|
63
63
|
if C.type==_J:R+=C.data.get(_C,'')
|
|
64
64
|
if F:print(f"[DEBUG] Yielding: {C.type}")
|
|
65
65
|
yield C.data
|
|
66
66
|
if hasattr(A,_Y)and A.tool_calls:
|
|
67
|
-
for C in
|
|
67
|
+
for C in bo(A.tool_calls,E,J):
|
|
68
68
|
if F:print(f"[DEBUG] Yielding from tool_calls: {C.type} took call: {A.tool_calls}")
|
|
69
69
|
yield C.data
|
|
70
70
|
elif hasattr(A,_B)and A.type=='tool':
|
|
71
71
|
if F:I=getattr(A,_A,_L);print(f"[DEBUG] Processing tool result: {I}")
|
|
72
|
-
for C in
|
|
72
|
+
for C in bp(A,E,J):
|
|
73
73
|
if F:print(f"[DEBUG] Yielding: {C.type}")
|
|
74
74
|
yield C.data
|
|
75
75
|
elif K==_Z:
|
|
@@ -99,17 +99,17 @@ def stream_handler(stream,emitter,tracker,debug=False):
|
|
|
99
99
|
else:A=B
|
|
100
100
|
if F:Y=type(A).__name__;print(f"[DEBUG] Event: {Y}")
|
|
101
101
|
if isinstance(A,(AIMessageChunk,AIMessage)):
|
|
102
|
-
for C in
|
|
102
|
+
for C in bn(A,E,J,S):
|
|
103
103
|
if C.type==_J:R+=C.data.get(_C,'')
|
|
104
104
|
if F:print(f"[DEBUG] Yielding: {C.type}")
|
|
105
105
|
yield C.data
|
|
106
106
|
if hasattr(A,_Y)and A.tool_calls:
|
|
107
|
-
for C in
|
|
107
|
+
for C in bo(A.tool_calls,E,J):
|
|
108
108
|
if F:print(f"[DEBUG] Yielding from tool_calls: {C.type}")
|
|
109
109
|
yield C.data
|
|
110
110
|
elif hasattr(A,_B)and A.type=='tool':
|
|
111
111
|
if F:I=getattr(A,_A,_L);print(f"[DEBUG] Processing tool result: {I}")
|
|
112
|
-
for C in
|
|
112
|
+
for C in bp(A,E,J):
|
|
113
113
|
if F:print(f"[DEBUG] Yielding: {C.type}")
|
|
114
114
|
yield C.data
|
|
115
115
|
elif K==_Z:
|
|
@@ -117,7 +117,7 @@ def stream_handler(stream,emitter,tracker,debug=False):
|
|
|
117
117
|
if O==_N:yield E.tool_call(I,Z,Q,P)
|
|
118
118
|
elif O==_e:yield E.tool_result(I,a,b,Q,P)
|
|
119
119
|
if F:print(_f)
|
|
120
|
-
def
|
|
120
|
+
def bn(chunk,emitter,tracker,stream_parser):
|
|
121
121
|
U='index';T='tool_use';S='reasoning';R='thinking';L='write_file';K=stream_parser;J=chunk;I=emitter;E=tracker;C=J.content
|
|
122
122
|
if isinstance(C,str):
|
|
123
123
|
if C:yield I.text(C);return
|
|
@@ -160,19 +160,19 @@ def bp(chunk,emitter,tracker,stream_parser):
|
|
|
160
160
|
E.append_json_delta(H,A.get(U,0))
|
|
161
161
|
if D==L:K.feed(H)
|
|
162
162
|
if D==L and H=='':K.reset()
|
|
163
|
-
def
|
|
163
|
+
def bq(block,emitter,tracker):
|
|
164
164
|
C=tracker;B=block;A=B.get(_K,'')
|
|
165
165
|
if A:
|
|
166
166
|
D=B.get(_A,'');E=B.get('input',{});F=E if isinstance(E,dict)else{};C.update(A,name=D,args=F)
|
|
167
167
|
if C.is_ready(A):C.mark_emitted(A);yield emitter.tool_call(D,F,A)
|
|
168
|
-
def
|
|
168
|
+
def bo(tool_calls,emitter,tracker):
|
|
169
169
|
B=tracker
|
|
170
170
|
for C in tool_calls:
|
|
171
171
|
A=C.get(_K,'')
|
|
172
172
|
if A:
|
|
173
173
|
D=C.get(_A,'');E=C.get(_F,{});F=E if isinstance(E,dict)else{};B.update(A,name=D,args_complete=True)
|
|
174
174
|
if B.is_ready(A):B.mark_emitted(A);yield emitter.tool_call(D,F,A)
|
|
175
|
-
def
|
|
175
|
+
def bp(chunk,emitter,tracker):
|
|
176
176
|
E=tracker;D=emitter;A=chunk;E.finalize_all()
|
|
177
177
|
for B in E.get_all():yield D.tool_call(B.name,B.args,B.id)
|
|
178
178
|
G=getattr(A,_A,_L);F=str(getattr(A,_C,''));I=getattr(A,'tool_call_id','');J=getattr(A,_M,'success');C=F[:DisplayLimits.TOOL_RESULT_MAX]
|
|
@@ -8,11 +8,12 @@ import os
|
|
|
8
8
|
import requests
|
|
9
9
|
from bs4 import BeautifulSoup
|
|
10
10
|
from ddgs import DDGS
|
|
11
|
-
from ddgs.exceptions import DDGSException
|
|
12
11
|
from langchain.tools import tool, ToolRuntime
|
|
13
12
|
from pydantic import BaseModel
|
|
14
13
|
|
|
15
14
|
sys.path.append(os.getcwd())
|
|
15
|
+
import logging
|
|
16
|
+
logging.getLogger("ddgs").setLevel(logging.ERROR)
|
|
16
17
|
|
|
17
18
|
|
|
18
19
|
|
|
@@ -46,7 +47,9 @@ def web_search(query: str, max_results: int = 3, runtime: ToolRuntime = None) ->
|
|
|
46
47
|
|
|
47
48
|
max_results = max(1, min(max_results, 10)) # Clamp between 1 and 10
|
|
48
49
|
|
|
50
|
+
# ddgs = DDGS()
|
|
49
51
|
ddgs = DDGS()
|
|
52
|
+
|
|
50
53
|
results_list = list(ddgs.text(query, max_results=max_results))
|
|
51
54
|
|
|
52
55
|
if not results_list:
|
|
@@ -61,8 +64,6 @@ def web_search(query: str, max_results: int = 3, runtime: ToolRuntime = None) ->
|
|
|
61
64
|
|
|
62
65
|
return "\n\n".join(results)
|
|
63
66
|
|
|
64
|
-
except DDGSException as e:
|
|
65
|
-
return f"Search failed: {str(e)}"
|
|
66
67
|
except Exception as e:
|
|
67
68
|
return f"Search error: {str(e)}"
|
|
68
69
|
|
|
@@ -148,10 +149,10 @@ if __name__ == "__main__":
|
|
|
148
149
|
search_result = web_search.invoke({"query": "LangChain v1.0 documentation", "max_results": 5})
|
|
149
150
|
print(search_result)
|
|
150
151
|
|
|
151
|
-
# 示ä¾2ļ¼č°ēØē½é”µå
容č·åå·„å
·
|
|
152
|
-
fetch_result = web_fetch.invoke({
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
})
|
|
156
|
-
print(fetch_result)
|
|
152
|
+
# # 示ä¾2ļ¼č°ēØē½é”µå
容č·åå·„å
·
|
|
153
|
+
# fetch_result = web_fetch.invoke({
|
|
154
|
+
# "url": "https://python.langchain.com/docs/get_started/introduction",
|
|
155
|
+
# "prompt": "Extract key features of LangChain v1.0"
|
|
156
|
+
# })
|
|
157
|
+
# print(fetch_result)
|
|
157
158
|
# pass
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
_L='custom'
|
|
2
|
+
_K='updates'
|
|
3
|
+
_J='thread_id'
|
|
4
|
+
_I='configurable'
|
|
5
|
+
_H='class:status'
|
|
6
|
+
_G='messages'
|
|
7
|
+
_F='class:footer'
|
|
8
|
+
_E='auto'
|
|
9
|
+
_D='description'
|
|
9
10
|
_C=False
|
|
10
11
|
_B=True
|
|
11
12
|
_A=None
|
|
@@ -23,6 +24,7 @@ from prompt_toolkit.layout.dimension import D
|
|
|
23
24
|
from prompt_toolkit.document import Document
|
|
24
25
|
from prompt_toolkit.styles import Style
|
|
25
26
|
from prompt_toolkit import Application
|
|
27
|
+
from prompt_toolkit.output import create_output
|
|
26
28
|
from rich.markdown import Markdown
|
|
27
29
|
from rich.columns import Columns
|
|
28
30
|
from rich.markup import render
|
|
@@ -40,12 +42,12 @@ from src.tui.utils.trender import display_tool_call,display_tool_result,display_
|
|
|
40
42
|
from langchain_core.messages import HumanMessage
|
|
41
43
|
from langgraph.types import Command
|
|
42
44
|
from dotenv import find_dotenv,load_dotenv
|
|
43
|
-
|
|
45
|
+
b=load_dotenv(find_dotenv())
|
|
44
46
|
class LiveChatUI:
|
|
45
|
-
def __init__(A,agent=_A,saver=_A,workspace=_A,**
|
|
46
|
-
def
|
|
47
|
-
def
|
|
48
|
-
F=model_status;E=sandbox_status;D=mcp_status;C=workspace;B=
|
|
47
|
+
def __init__(A,agent=_A,saver=_A,workspace=_A,**C):B='#afafff';A.agent=agent;A.saver=saver;A.kwargs=C;A.workspace=re.sub('^(\\/Users\\/[^/]+|\\/home\\/[^/]+)','~',workspace);A.thread_id=1;A.token_count=0;A.mode=_E;A.context=C.get('context',_A);A.instruction_manager=C.get('instruction_manager',_A);A.spinner=Spinner('block');A.max_input_lines=10;A.cancel_event=_A;A.logo_label=Label(LOGO.format(A.workspace),style='class:logo');A.begin_items=[A.logo_label];A.begin_area=HSplit([*A.begin_items],padding=1);A.log_control=ScrollableFormattedLogControl();A.output_area=Window(content=A.log_control,wrap_lines=_B,always_hide_cursor=_C,height=D(weight=1));A.status_label=FormattedTextControl(text=[(_H,' ē¶ę: ēå¾
č¾å
„ | Tokens: 0 ļ¼ā„ + ā ę¢č” Esc äøę ctrl + c éåŗļ¼')]);F=FormattedTextControl(text=[('class:spinner',f"{A.spinner.current_frame()}")],show_cursor=_C);G=FormattedTextControl(text=[(_F,f"mode: {A.mode}")]);A.status_bar=VSplit([Window(F,width=D(weight=5),dont_extend_width=_B,dont_extend_height=_B,height=D(weight=1)),Window(A.status_label,width=D(weight=85),height=D(weight=1)),Window(G,width=D(weight=10),dont_extend_width=_B,dont_extend_height=_B,height=D(weight=1))],width=D(weight=100));A.input_box=TextArea(height=1,prompt='> ',multiline=_B,wrap_lines=_B,scrollbar=_B,style='class:input_box');A.input_box.buffer.on_text_changed+=lambda _:A.update_input_area_height(b);A.kb=KeyBindings();A.a();H=Frame(body=A.input_box,style='class:frame');A.input_items=[A.status_bar,H];A.input_area=HSplit([*A.input_items],padding=0);A.interact_items=[];A.interact_area=HSplit([*A.interact_items],padding=1);E=_F;A.footer=VSplit([Window(FormattedTextControl([(E,f"{A.workspace} (main) ")]),width=D(weight=50)),Window(FormattedTextControl([(E,f"MCP: (0/0) ")]),width=D(weight=20)),Window(FormattedTextControl([(E,'Env: (local) ')]),width=D(weight=20)),Window(FormattedTextControl([(E,f"Model: kimi-k2-0711-preview ")]),wrap_lines=_B,dont_extend_width=_C,always_hide_cursor=_B,width=D(weight=10))],width=D(weight=100),height=1);A.suggest_items=[A.footer];A.suggest_area=HSplit([*A.suggest_items],padding=0);A.logo_area=DynamicContainer(lambda:A.begin_area);A.display_container=DynamicContainer(lambda:A.output_area);A.input_container=DynamicContainer(lambda:A.input_area);A.status_area=DynamicContainer(lambda:A.suggest_area);A.layout=Layout(HSplit([A.logo_area,A.output_area,A.interact_area,A.input_container,A.status_area],padding=0),focused_element=A.input_box);A.style=Style.from_dict({'logo':B,'output':B,'input_box':B,'status':B,'frame.border':B,'suggestions':B,'footer':B,'suggestion.label':B,'suggestion.desc':'#5f5f5f','spinner':B,'suggestion.selected':'bold #00afff'});I=create_output();A.app=Application(layout=A.layout,key_bindings=A.kb,style=A.style,output=I,full_screen=_C,mouse_support=_B);A.app.input_area=A.input_box;A.app.kb=A.kb;A.interrupt_tools=C.get('interrupt_tools',[]);A.toolcall_mode='manul'
|
|
48
|
+
def c(A,role='user',spinner='ā',status='',tokens=0):A.status_label.text=[(_H,f" ē¶ę: {status} | ({role}) | Tokens: {tokens} (esc + ā ę¢č” ę两欔 esc äøę ctrl + c éåŗļ¼")];A.app.invalidate()
|
|
49
|
+
def e(A,workspace=_A,mcp_status=_A,sandbox_status=_A,model_status=_A):
|
|
50
|
+
F=model_status;E=sandbox_status;D=mcp_status;C=workspace;B=_F
|
|
49
51
|
if C is not _A:A._footer_workspace.text=[(B,f"{C}(main) ")]
|
|
50
52
|
if D is not _A:A._footer_context.text=[(B,f"{D} ")]
|
|
51
53
|
if E is not _A:A._footer_env.text=[(B,f"Env: {E} ")]
|
|
@@ -72,65 +74,79 @@ class LiveChatUI:
|
|
|
72
74
|
def B(event):
|
|
73
75
|
if A.cancel_event:A.cancel_event.set()
|
|
74
76
|
async def _handle_submit(A,text,context=_A):
|
|
75
|
-
D='light_steel_blue';C=
|
|
76
|
-
if A.logo_label in A.begin_items:A.begin_items.remove(A.logo_label);A.begin_area.children=list(A.begin_items);
|
|
77
|
-
if
|
|
78
|
-
if
|
|
79
|
-
A.spinner.start();A.
|
|
80
|
-
|
|
77
|
+
D='light_steel_blue';C=context;B=text
|
|
78
|
+
if A.logo_label in A.begin_items:A.begin_items.remove(A.logo_label);A.begin_area.children=list(A.begin_items);J=render_info(LOGO.format(A.workspace),style=D,markdown=_C);A.log_control.append_text(J);A.app.invalidate()
|
|
79
|
+
if B.strip()in['quit','exit','q']:get_app().exit();return
|
|
80
|
+
if B.strip()in['/clear','clear']:A.clear();return
|
|
81
|
+
A.spinner.start();A.d('ā user',f"ā {B}",style='light_salmon3');await asyncio.sleep(.05)
|
|
82
|
+
if B.strip()in['/commands']and A.instruction_manager:
|
|
83
|
+
E=[]
|
|
84
|
+
for F in A.instruction_manager.list_instructions():E.append(f"/{F.name}: - {F.settings[_D]}")
|
|
85
|
+
K='\n'.join(E);A.d('ā bot',K,style=D,markdown=_B);return
|
|
86
|
+
if A.instruction_manager:G=A.instruction_manager.parse(B);H,I=G['executed_instruction'],G['message'];B=f"""
|
|
87
|
+
[注ę]: ę§č”ēØę·čÆ·ę±åæ
é”»äø„ę ¼éµå¾Ŗå¦äøåå:
|
|
88
|
+
{H}
|
|
89
|
+
|
|
90
|
+
ēØę·čÆ·ę±:
|
|
91
|
+
{I}"""if H else I
|
|
92
|
+
C=A.context if C is _A else C;L=await A._handle_stream('ā bot',A._stream_generate(B,C),style=D,markdown=_B,context=C);A.spinner.stop();A.c(spinner='',status='ēå¾
č¾å
„',tokens=A.token_count);A.app.layout.focus(A.input_box);return L
|
|
93
|
+
def d(A,sender,message,style='green',markdown=_C):D=markdown;C=style;B=message;E=Markdown(B)if D else Text(B,style=C);F=render_panel(sender,E,C,D);A.log_control.append_text(F);A.app.invalidate()
|
|
81
94
|
async def _stream_generate(A,prompt,context=_A):
|
|
82
|
-
B=A.agent.astream({
|
|
95
|
+
B=A.agent.astream({_G:[HumanMessage(content=prompt)]},config={_I:{_J:A.thread_id}},stream_mode=[_G,_K,_L],context=context);A.cancel_event=asyncio.Event()
|
|
83
96
|
async for C in astream_handler(B,interrupt_tools=A.interrupt_tools,tool_mode=A.toolcall_mode):
|
|
84
97
|
if A.cancel_event and A.cancel_event.is_set():A.cancel_event.clear();A.cancel_event=_A;return
|
|
85
98
|
yield C
|
|
86
99
|
async def _resume_generate(A,interrupt_id,decisions,context=_A):
|
|
87
|
-
B=A.agent.astream(Command(resume={interrupt_id:{'decisions':decisions}}),config={
|
|
100
|
+
B=A.agent.astream(Command(resume={interrupt_id:{'decisions':decisions}}),config={_I:{_J:A.thread_id}},stream_mode=[_G,_K,_L],context=context);A.cancel_event=asyncio.Event()
|
|
88
101
|
async for C in astream_handler(B,interrupt_tools=A.interrupt_tools,tool_mode=A.toolcall_mode):
|
|
89
102
|
if A.cancel_event and A.cancel_event.is_set():A.cancel_event.clear();A.cancel_event=_A
|
|
90
103
|
yield C
|
|
91
104
|
async def _handle_stream(D,sender,stream,style='green',markdown=_C,items=_A,context=_A):
|
|
92
|
-
|
|
93
|
-
if A is _A:D.log_control.append_text(render_panel(
|
|
105
|
+
m='value';l='parent_id';i=context;h='label';g='tool_result';f='text';e='thinking';c=markdown;b=style;a=sender;Z='success';Y='tool_call';P='args';O='name';J='type';G='content';A=items;Q,V='','';t=A is not _A
|
|
106
|
+
if A is _A:D.log_control.append_text(render_panel(a,'',b,c))
|
|
94
107
|
A=A if A else[]
|
|
95
108
|
async for B in stream:
|
|
96
|
-
if B[
|
|
97
|
-
if len(A)>0 and A[-1][1]==
|
|
98
|
-
else:
|
|
99
|
-
elif B[
|
|
100
|
-
if len(A)>0 and A[-1][1]==
|
|
101
|
-
else:Q=B[G];
|
|
102
|
-
elif B[
|
|
103
|
-
elif B[
|
|
104
|
-
|
|
105
|
-
if
|
|
109
|
+
if B[J]==e:
|
|
110
|
+
if len(A)>0 and A[-1][1]==e:V+=B[G];K=markdown_to_wrapped_text(V);A[-1][0]=K
|
|
111
|
+
else:V=B[G];K=markdown_to_wrapped_text(V);A.append([K,e,_A,B,[]])
|
|
112
|
+
elif B[J]==f:
|
|
113
|
+
if len(A)>0 and A[-1][1]==f:Q+=B[G];K=markdown_to_wrapped_text(f"{Q}");A[-1][0]=K
|
|
114
|
+
else:Q=B[G];K=markdown_to_wrapped_text(f"{Q}");A.append([K,f,_A,B,[]])
|
|
115
|
+
elif B[J]=='token_usage':u=B['input_toks'];v=B['output_toks'];n=B['total_toks'];D.token_count=n
|
|
116
|
+
elif B[J]==Y:
|
|
117
|
+
R=B[O];W=B[P];H=B['id'];I=B[l]
|
|
118
|
+
if I is _A:F=display_tool_call(R,W,[]);A.append([F,Y,H,B,[]]);A.append([Text('',''),'margin',_A,_A,[]])
|
|
106
119
|
else:
|
|
107
|
-
C=index_(A,lambda x:x[2]==
|
|
120
|
+
C=index_(A,lambda x:x[2]==I and x[1]==Y)
|
|
108
121
|
if C is _A:continue
|
|
109
|
-
|
|
110
|
-
elif B[
|
|
111
|
-
|
|
122
|
+
E=A[C];S=E[3][O];T=E[3][P];A[C][-1].append([_A,Y,H,B,[]]);F=display_tool_call(S,T,A[C][-1]);A[C][0]=F
|
|
123
|
+
elif B[J]==g:
|
|
124
|
+
R=B[O];H=B['id'];I=B[l]
|
|
125
|
+
try:L=index_(A,lambda x:x[2]==H);o=A[L][3]
|
|
126
|
+
except Exception:D.log_control.append_text(f"[DEBUG] tool_result: {R}, {H}, {I}")
|
|
127
|
+
W=o[P];X=B[Z]
|
|
112
128
|
if X==Z:
|
|
113
|
-
if
|
|
129
|
+
if I is _A:U=B[G];F=display_tool_result(R,W,U,A[L][-1]);A[L]=[F,g,H,B,A[L][-1]]
|
|
114
130
|
else:
|
|
115
|
-
C=index_(A,lambda x:x[2]==
|
|
131
|
+
C=index_(A,lambda x:x[2]==I)
|
|
116
132
|
if C is _A:continue
|
|
117
|
-
E=A[C];
|
|
133
|
+
E=A[C];S=E[3][O];T=E[3][P];M=index_(E[-1],lambda x:x[2]==H)
|
|
118
134
|
if M is _A:continue
|
|
119
|
-
N=E[-1][M];N[Z]=X;N[G]=B[G];A[C][-1][M]=N;F=display_tool_result(
|
|
135
|
+
N=E[-1][M];N[3][Z]=X;N[3][G]=B[G];A[C][-1][M]=N;F=display_tool_result(S,T,U,A[C][-1]);A[C][0]=F
|
|
120
136
|
elif X=='error':
|
|
121
|
-
if
|
|
137
|
+
if I is _A:U=B[G];F=display_tool_error(R,W,U,A[L][-1]);A[L]=[F,g,H,B,A[L][-1]]
|
|
122
138
|
else:
|
|
123
|
-
C=index_(A,lambda x:x[2]==
|
|
139
|
+
C=index_(A,lambda x:x[2]==I)
|
|
124
140
|
if C is _A:continue
|
|
125
|
-
E=A[C];
|
|
141
|
+
E=A[C];S=E[3][O];T=E[3][P];M=index_(E[-1],lambda x:x[2]==H)
|
|
126
142
|
if M is _A:continue
|
|
127
|
-
N=E[-1][M];N[Z]=X;N[G]=B[G];A[C][-1][M]=N;F=display_tool_error(
|
|
128
|
-
elif B[
|
|
129
|
-
elif B[
|
|
130
|
-
D.spinner.stop();
|
|
131
|
-
for
|
|
132
|
-
D.spinner.start();await D._handle_stream(
|
|
133
|
-
|
|
143
|
+
N=E[-1][M];N[Z]=X;N[G]=B[G];A[C][-1][M]=N;F=display_tool_error(S,T,U,A[C][-1]);A[C][0]=F
|
|
144
|
+
elif B[J]=='done':0
|
|
145
|
+
elif B[J]=='interrupt':
|
|
146
|
+
D.spinner.stop();j=[];p=B['interrupt_id']
|
|
147
|
+
for d in B[m][m]['action_requests']:w=d[O];x=d[P];y=d[_D];q=await D._handle_human_interrupt(message=f" å
许ę§č”å½åå½ę°ä¹ļ¼ ",options=[{h:'ęÆēļ¼å
许å½åå½ę°ę§č”',_D:''},{h:'ęÆēļ¼ę»ęÆå
许ę§č”ļ¼å½å对čÆčæēØäøäøåę示',_D:''},{h:'äø, äøå
许å½åå½ę°ę§č”',_D:''}]);k=['approve',_E,'reject'][q];D.toolcall_mode=_E if k==_E else'manual';j.append({J:k})
|
|
148
|
+
D.spinner.start();await D._handle_stream(a,D._resume_generate(p,j,i),style=b,markdown=c,items=A,context=i);break
|
|
149
|
+
r=Columns([A[0]for A in A],column_first=_B,expand=_B);D.log_control.update_last(render_panel(a,r,b,c));D.app.invalidate();await asyncio.sleep(.03);s='';D.c(spinner=s,status='ę£åØēę ...',tokens=D.token_count)
|
|
134
150
|
return Q
|
|
135
151
|
async def _handle_human_interrupt(A,message,options):
|
|
136
152
|
E=asyncio.get_event_loop();C=E.create_future();D=A.app.key_bindings
|
|
@@ -19,20 +19,20 @@ from prompt_toolkit.layout import Layout,HSplit
|
|
|
19
19
|
from prompt_toolkit.styles import Style
|
|
20
20
|
from prompt_toolkit import Application
|
|
21
21
|
class InterruptSelector:
|
|
22
|
-
def __init__(A,description,options,callback):B=description;A.options=options;A.description=B;A.selected_index=0;A.callback=callback;A.rows=A.
|
|
23
|
-
def
|
|
24
|
-
def
|
|
22
|
+
def __init__(A,description,options,callback):B=description;A.options=options;A.description=B;A.selected_index=0;A.callback=callback;A.rows=A.q();A.list_container=HSplit(A.rows,padding=0);A.markdown=A.t(B);C=Window(content=A.markdown.content,height=A.markdown.height,dont_extend_height=_B,style='class:desc');D=Frame(body=C);A.container=HSplit([C,A.list_container]);A.kb=KeyBindings();A.s()
|
|
23
|
+
def t(C,content):A=StringIO();B=Console(file=A,width=80,force_terminal=_B,color_system='truecolor');B.print(Align.left(Markdown(content)),justify='left');return Window(content=FormattedTextControl(ANSI(A.getvalue())),height=D(min=1))
|
|
24
|
+
def q(A):
|
|
25
25
|
E='class:suggestion.selected';B=[]
|
|
26
26
|
for(F,C)in enumerate(A.options):D=F==A.selected_index;G='> 'if D else' ';H=E if D else'class:suggestion.label';I='class:suggestion.desc';J=VSplit([Window(FormattedTextControl([(E,G)]),width=2),Window(FormattedTextControl([(H,C[_A])]),width=60),Window(FormattedTextControl([(I,C[_C])]),wrap_lines=_B,dont_extend_width=False,always_hide_cursor=_B)],height=1);B.append(J)
|
|
27
27
|
return B
|
|
28
|
-
def
|
|
28
|
+
def p(A):A.rows=A.q();A.list_container.children=A.rows;get_app().invalidate()
|
|
29
29
|
def s(A):
|
|
30
30
|
@A.kb.add('up')
|
|
31
31
|
def B(event):
|
|
32
|
-
if A.selected_index>0:A.selected_index-=1;A.
|
|
32
|
+
if A.selected_index>0:A.selected_index-=1;A.p()
|
|
33
33
|
@A.kb.add('down')
|
|
34
34
|
def C(event):
|
|
35
|
-
if A.selected_index<len(A.options)-1:A.selected_index+=1;A.
|
|
35
|
+
if A.selected_index<len(A.options)-1:A.selected_index+=1;A.p()
|
|
36
36
|
@A.kb.add('enter')
|
|
37
37
|
def D(event):A.callback(A.selected_index)
|
|
38
38
|
async def demo():
|
|
@@ -6,22 +6,22 @@ from prompt_toolkit.layout.controls import UIControl,UIContent
|
|
|
6
6
|
from prompt_toolkit.data_structures import Point
|
|
7
7
|
from prompt_toolkit.formatted_text import ANSI
|
|
8
8
|
class ScrollableFormattedLogControl(FormattedTextControl):
|
|
9
|
-
def __init__(A):A.lines=[];A.scroll_offset=0;A._height=0;A.last_count=0;super().__init__(A.
|
|
9
|
+
def __init__(A):A.lines=[];A.scroll_offset=0;A._height=0;A.last_count=0;super().__init__(A.z,focusable=True,show_cursor=False)
|
|
10
10
|
def clear(A):A.lines=[];A.scroll_offset=0;A.last_count=0;A._height=0
|
|
11
|
-
def append_text(A,ansi_text):B=ansi_text.splitlines();A.lines.extend(B);A.last_count=len(B);A.
|
|
11
|
+
def append_text(A,ansi_text):B=ansi_text.splitlines();A.lines.extend(B);A.last_count=len(B);A.y()
|
|
12
12
|
def update_last(A,ansi_text):
|
|
13
13
|
B=ansi_text.splitlines()
|
|
14
14
|
if A.lines:A.lines=A.lines[:-A.last_count]+B
|
|
15
15
|
else:A.lines=B
|
|
16
|
-
A.last_count=len(B);A.
|
|
16
|
+
A.last_count=len(B);A.y()
|
|
17
17
|
def refresh_scroll(A):
|
|
18
18
|
if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
|
|
19
|
-
def
|
|
19
|
+
def y(A):
|
|
20
20
|
if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
|
|
21
21
|
def x(A,amount):
|
|
22
22
|
if A._height:B=max(0,len(A.lines)-A._height);A.scroll_offset=max(0,min(A.scroll_offset+amount,B))
|
|
23
23
|
def is_focusable(A):return True
|
|
24
|
-
def
|
|
24
|
+
def z(A):
|
|
25
25
|
C=A._height or 100;D=A.lines[A.scroll_offset:A.scroll_offset+C];B=[]
|
|
26
26
|
for E in D:F=sanitize_ansi_text(E);B.extend(ANSI(F).__pt_formatted_text__());B.append(('','\n'))
|
|
27
27
|
return B
|
|
@@ -34,15 +34,15 @@ class ScrollableFormattedLogControl(FormattedTextControl):
|
|
|
34
34
|
class ScrollableLogControl(UIControl):
|
|
35
35
|
def __init__(A):A.lines=[];A.scroll_offset=0;A.visible_lines=[];A._height=0;A.last_count=0
|
|
36
36
|
def clear(A):A.visible_lines=[];A.lines=[];A.scroll_offset=0;A.last_count=0;A._height=0
|
|
37
|
-
def append_text(A,ansi_text):B=ansi_text.splitlines();A.lines.extend(B);A.last_count=len(B);A.
|
|
37
|
+
def append_text(A,ansi_text):B=ansi_text.splitlines();A.lines.extend(B);A.last_count=len(B);A.y()
|
|
38
38
|
def update_last(A,ansi_text):
|
|
39
39
|
B=ansi_text.splitlines()
|
|
40
40
|
if A.lines:A.lines=A.lines[:-A.last_count]+B
|
|
41
41
|
else:A.lines=B
|
|
42
|
-
A.last_count=len(B);A.
|
|
42
|
+
A.last_count=len(B);A.y()
|
|
43
43
|
def refresh_scroll(A):
|
|
44
44
|
if A._height:A.scroll_offset=max(0,len(A.lines)-A._height)
|
|
45
|
-
def
|
|
45
|
+
def y(A):A.scroll_offset=max(0,len(A.lines)-A._height)
|
|
46
46
|
def x(A,amount):A.scroll_offset=max(0,min(A.scroll_offset+amount,max(0,len(A.lines)-A._height)))
|
|
47
47
|
def is_focusable(A):return True
|
|
48
48
|
def create_content(A,width,height):B=height;A._height=B;A.visible_lines=A.lines[A.scroll_offset:A.scroll_offset+B];return UIContent(get_line=A.get_line,line_count=len(A.visible_lines),cursor_position=Point(0,len(A.visible_lines)-1))
|
|
@@ -27,8 +27,8 @@ from src.tui.components.tdiff import render_diff_as_markdown
|
|
|
27
27
|
from src.tui.components.tdisplay import render_content_with_line_limit
|
|
28
28
|
from src.tui.utils.render import markdown_to_wrapped_text
|
|
29
29
|
def display_tool_call(tool_name,args,events=[]):
|
|
30
|
-
C=tool_name;A=events;E=format_tool_compact(C,args);D=
|
|
31
|
-
if A and len(A)>0:F=display_sub_panel(D,
|
|
30
|
+
C=tool_name;A=events;E=format_tool_compact(C,args);D=n(C,args);B=Tree(Text(_I,style=_J)+Text(f"{E}",style=_C),guide_style=_D)
|
|
31
|
+
if A and len(A)>0:F=display_sub_panel(D,sub_events=A);B.add(F)
|
|
32
32
|
else:B.add(D)
|
|
33
33
|
return B
|
|
34
34
|
def display_tool_result(tool_name,args=_E,result=_E,events=[]):
|
|
@@ -40,13 +40,13 @@ def display_tool_result(tool_name,args=_E,result=_E,events=[]):
|
|
|
40
40
|
elif C==_L and isinstance(A,dict):B=k(A)
|
|
41
41
|
elif C in[_M]and isinstance(A,dict):B=k(A)
|
|
42
42
|
elif C==_H and isinstance(A,dict):B=h(A,D)
|
|
43
|
-
elif C==_N and isinstance(A,dict):B=
|
|
44
|
-
elif C==_O and isinstance(A,dict):B=
|
|
45
|
-
elif C==_P and isinstance(A,dict):B=
|
|
46
|
-
else:B=
|
|
43
|
+
elif C==_N and isinstance(A,dict):B=i(A,D)
|
|
44
|
+
elif C==_O and isinstance(A,dict):B=m(A,D)
|
|
45
|
+
elif C==_P and isinstance(A,dict):B=f(A,D)
|
|
46
|
+
else:B=j(A,D)
|
|
47
47
|
except Exception as I:import traceback as J;B=Text(f"Error: {str(I)}\n{J.format_exc()}",style='red')
|
|
48
48
|
F=Tree(Text(_I,style=_J)+Text(f"{H}",style=_C),guide_style=_D)
|
|
49
|
-
if E and len(E)>0:K=display_sub_panel(B,
|
|
49
|
+
if E and len(E)>0:K=display_sub_panel(B,sub_events=E);F.add(K)
|
|
50
50
|
else:F.add(B)
|
|
51
51
|
return F
|
|
52
52
|
def display_tool_error(tool_name,args,error,events=[]):
|
|
@@ -55,7 +55,7 @@ def display_tool_error(tool_name,args,error,events=[]):
|
|
|
55
55
|
elif'file not found'in A.lower():A+='\nš” Check if the file path is correct'
|
|
56
56
|
elif'command not found'in A.lower():A+='\nš” Check if the command is installed and in PATH'
|
|
57
57
|
D=Text(A,style='red');C=Tree(Text(_I,style=_J)+Text(f"{E}",style=_C),guide_style=_D)
|
|
58
|
-
if B and len(B)>0:F=display_sub_panel(D,
|
|
58
|
+
if B and len(B)>0:F=display_sub_panel(D,sub_events=B);C.add(F)
|
|
59
59
|
else:C.add(D)
|
|
60
60
|
return C
|
|
61
61
|
def format_tool_compact(name,args):
|
|
@@ -101,33 +101,33 @@ def format_tool_compact(name,args):
|
|
|
101
101
|
I=', '.join(M)
|
|
102
102
|
if len(I)>50:I=I[:47]+_B
|
|
103
103
|
return f"{J}({I})"
|
|
104
|
-
def
|
|
104
|
+
def n(tool_name,arguments):
|
|
105
105
|
D=' Will search for pattern';C=arguments;B='bold grey';A=tool_name.lower()
|
|
106
106
|
if A==_H:return Text(f"running ...",style=B)
|
|
107
107
|
if A==_M:return Text(f" Executing ...",style=B)
|
|
108
|
-
elif A==_L:return
|
|
109
|
-
elif A==_K:return
|
|
108
|
+
elif A==_L:return g(C)
|
|
109
|
+
elif A==_K:return o(C)
|
|
110
110
|
elif A in[_N,_O]:return Text(D,style=B)
|
|
111
111
|
elif A==_P:return Text(D,stype=B)
|
|
112
112
|
else:return Text(' Executing ...',style=B)
|
|
113
113
|
def display_sub_panel(result=_E,sub_events=[]):
|
|
114
|
-
H='success';
|
|
115
|
-
for(
|
|
116
|
-
E=D['name'];F=json.dumps(D['args'])[:20];G=D[H
|
|
117
|
-
if G==H:
|
|
118
|
-
elif G=='error':
|
|
119
|
-
elif G==
|
|
120
|
-
if
|
|
121
|
-
if isinstance(
|
|
122
|
-
else:A.append(
|
|
114
|
+
I='calling';H='success';C=result;A=[]
|
|
115
|
+
for(M,D)in enumerate(sub_events):
|
|
116
|
+
E=D[3]['name'];F=json.dumps(D[3]['args'])[:20];G=D[3].get(H,I);N=D[3].get(_R,'')
|
|
117
|
+
if G==H:B=Tree(Text('ā ',style=_Q)+Text(f" {E}({F})",style=_C),guide_style=_D);A.append(B)
|
|
118
|
+
elif G=='error':B=Tree(Text('ā ',style='bold red')+Text(f" {E}({F})",style=_C),guide_style=_D);A.append(B)
|
|
119
|
+
elif G==I:B=Tree(Text('ā ',style=_Q)+Text(f" {E}({F})",style=_C),guide_style=_D);A.append(B)
|
|
120
|
+
if C:
|
|
121
|
+
if isinstance(C,str):A.append(markdown_to_wrapped_text(f"{C[:200]}",prefix=_E))
|
|
122
|
+
else:A.append(C)
|
|
123
123
|
else:A.append(markdown_to_wrapped_text(f"calling ...",prefix=_E))
|
|
124
|
-
|
|
125
|
-
def
|
|
124
|
+
J=Columns(A,column_first=True,expand=True);K=Box(' \n \n \n \n \n \n \n ');L=Panel(J,title_align='left',box=K);return L
|
|
125
|
+
def o(arguments):
|
|
126
126
|
A=arguments;B=A.get(_F,'');C=A.get('old_string','');D=A.get('new_string','');E=''
|
|
127
127
|
if os.path.exists(B):
|
|
128
128
|
with open(B,'r',encoding='utf-8')as F:G=F.read()
|
|
129
129
|
H=D if C==''else G.replace(C,D,1);I=render_diff_as_markdown(E,H);return I
|
|
130
|
-
def
|
|
130
|
+
def g(arguments):
|
|
131
131
|
D=arguments;A=D.get(_F,'');B=D.get(_R,'')
|
|
132
132
|
if os.path.exists(A):C=open(A,'r').read()
|
|
133
133
|
else:C=''
|
|
@@ -163,7 +163,7 @@ def h(arguments,result):
|
|
|
163
163
|
E=F-D
|
|
164
164
|
if E>0:B.append(f" ... and {E} more lines")
|
|
165
165
|
return Text(_A.join(B),style=_G)
|
|
166
|
-
def
|
|
166
|
+
def i(arguments,result):
|
|
167
167
|
C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
|
|
168
168
|
for(H,A)in enumerate(G):
|
|
169
169
|
I=''if H==0 else''
|
|
@@ -172,7 +172,7 @@ def m(arguments,result):
|
|
|
172
172
|
E=F-D
|
|
173
173
|
if E>0:B.append(f" ... and {E} more lines")
|
|
174
174
|
return Text(_A.join(B),style=_G)
|
|
175
|
-
def
|
|
175
|
+
def m(arguments,result):
|
|
176
176
|
C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
|
|
177
177
|
for(H,A)in enumerate(G):
|
|
178
178
|
I=''if H==0 else''
|
|
@@ -181,7 +181,7 @@ def o(arguments,result):
|
|
|
181
181
|
E=F-D
|
|
182
182
|
if E>0:B.append(f" ... and {E} more lines")
|
|
183
183
|
return Text(_A.join(B),style=_G)
|
|
184
|
-
def
|
|
184
|
+
def f(arguments,result):
|
|
185
185
|
C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
|
|
186
186
|
for(H,A)in enumerate(G):
|
|
187
187
|
I=''if H==0 else''
|
|
@@ -190,7 +190,7 @@ def i(arguments,result):
|
|
|
190
190
|
E=F-D
|
|
191
191
|
if E>0:B.append(f" ... and {E} more lines")
|
|
192
192
|
return Text(_A.join(B),style=_G)
|
|
193
|
-
def
|
|
193
|
+
def j(arguments,result):
|
|
194
194
|
B=result;A=str(B)if B else'tool completed successfully'
|
|
195
195
|
if len(A)>500:C=A[:500]+'\n ... (truncated)'
|
|
196
196
|
else:C=A
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
_F='system'
|
|
2
|
+
_E='%a %b %d %Y %H:%M:%S %z'
|
|
3
|
+
_D='template'
|
|
4
|
+
_C='input_variables'
|
|
5
|
+
_B='prompt'
|
|
6
|
+
_A=None
|
|
1
7
|
from typing import Optional,List,Any,Dict,Annotated,Literal
|
|
2
8
|
from datetime import datetime
|
|
3
9
|
from langchain_core.prompts.loading import load_prompt_from_config
|
|
4
10
|
from langchain_core.messages import BaseMessage
|
|
5
11
|
from langgraph.graph import MessagesState
|
|
6
12
|
from langchain_core.prompts import ChatPromptTemplate,MessagesPlaceholder,SystemMessagePromptTemplate,PromptTemplate
|
|
7
|
-
def
|
|
8
|
-
|
|
13
|
+
def apply_prompt(prompt,state=_A,base_prompt=_A,format_instruction=_A,**F):
|
|
14
|
+
E=format_instruction;D=base_prompt;C=state;A=prompt;G={'_type':_B,_C:[],_D:A};A=load_prompt_from_config(G).partial(CURRENT_TIME=datetime.now().strftime(_E));H=SystemMessagePromptTemplate(prompt=A);B=[H]
|
|
9
15
|
if D:B.append(SystemMessagePromptTemplate(prompt=PromptTemplate(template=D)))
|
|
10
|
-
if E:B.append((
|
|
11
|
-
A=ChatPromptTemplate.from_messages(B).partial(**
|
|
16
|
+
if E:B.append((_F,f"{E}"))
|
|
17
|
+
A=ChatPromptTemplate.from_messages(B).partial(**F);A=A.format(**C)if C else A.format(**{});return A
|
|
18
|
+
def apply_template(agents_config,domain='',prompt_name='general',state=_A,base_prompt=_A,format_instruction=_A,**F):
|
|
19
|
+
E=format_instruction;D=base_prompt;C=state;G=agents_config[domain];H=G['members'][prompt_name];I={'_type':_B,_C:[],_D:H[_B]};A=load_prompt_from_config(I).partial(CURRENT_TIME=datetime.now().strftime(_E));J=SystemMessagePromptTemplate(prompt=A);B=[J]
|
|
20
|
+
if D:B.append(SystemMessagePromptTemplate(prompt=PromptTemplate(template=D)))
|
|
21
|
+
if E:B.append((_F,f"{E}"))
|
|
22
|
+
A=ChatPromptTemplate.from_messages(B).partial(**F);A=A.format(**C)if C else A.format(**{});return A
|