@brandon_9527/tcode 1.0.2 ā 1.0.6
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 +71 -2
- package/dist/python-src/main.py +440 -3
- package/dist/python-src/pyproject.toml +3 -2
- 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/core/deepagents.py +1 -1
- 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/middlewares/dynamic_content.py +66 -0
- package/dist/python-src/src/middlewares/hitl.py +3 -3
- package/dist/python-src/src/middlewares/inject_content.py +0 -0
- 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 +37 -37
- 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 +19 -19
- package/dist/python-src/src/stream/handler.py +105 -78
- package/dist/python-src/src/stream/handler_with_tracker.py +7 -7
- package/dist/python-src/src/tools/tools.py +2 -2
- package/dist/python-src/src/tools/web.py +10 -9
- package/dist/python-src/src/tui/chatui.py +57 -45
- package/dist/python-src/src/tui/components/tlist.py +6 -6
- package/dist/python-src/src/tui/demo.py +22 -0
- package/dist/python-src/src/tui/utils/trender.py +32 -32
- package/dist/python-src/src/utils/prompt.py +15 -4
- package/dist/python-src/uv.lock +2019 -2098
- 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,7 +59,7 @@ 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
|
|
@@ -69,7 +69,7 @@ async def astream_handler(stream,emitter,tracker,debug=False):
|
|
|
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 bo(A,E,J):
|
|
73
73
|
if F:print(f"[DEBUG] Yielding: {C.type}")
|
|
74
74
|
yield C.data
|
|
75
75
|
elif K==_Z:
|
|
@@ -99,7 +99,7 @@ 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
|
|
@@ -109,7 +109,7 @@ def stream_handler(stream,emitter,tracker,debug=False):
|
|
|
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 bo(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,7 +160,7 @@ 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 bp(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)
|
|
@@ -172,7 +172,7 @@ def bq(tool_calls,emitter,tracker):
|
|
|
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 bo(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]
|
|
@@ -445,10 +445,10 @@ def grep(pattern: str, path: str, runtime: ToolRuntime = None) -> str:
|
|
|
445
445
|
cwd = runtime.context.working_directory
|
|
446
446
|
|
|
447
447
|
if runtime.context.sandbox:
|
|
448
|
-
original_path, path = container2local(
|
|
448
|
+
original_path, path = container2local(path, cwd)
|
|
449
449
|
search_path = resolve_path(path, cwd)
|
|
450
450
|
else:
|
|
451
|
-
search_path = resolve_path(
|
|
451
|
+
search_path = resolve_path(path, cwd)
|
|
452
452
|
|
|
453
453
|
|
|
454
454
|
try:
|
|
@@ -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
|
|
@@ -40,12 +41,12 @@ from src.tui.utils.trender import display_tool_call,display_tool_result,display_
|
|
|
40
41
|
from langchain_core.messages import HumanMessage
|
|
41
42
|
from langgraph.types import Command
|
|
42
43
|
from dotenv import find_dotenv,load_dotenv
|
|
43
|
-
|
|
44
|
+
d=load_dotenv(find_dotenv())
|
|
44
45
|
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=
|
|
46
|
+
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(d);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'});A.app=Application(layout=A.layout,key_bindings=A.kb,style=A.style,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'
|
|
47
|
+
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()
|
|
48
|
+
def e(A,workspace=_A,mcp_status=_A,sandbox_status=_A,model_status=_A):
|
|
49
|
+
F=model_status;E=sandbox_status;D=mcp_status;C=workspace;B=_F
|
|
49
50
|
if C is not _A:A._footer_workspace.text=[(B,f"{C}(main) ")]
|
|
50
51
|
if D is not _A:A._footer_context.text=[(B,f"{D} ")]
|
|
51
52
|
if E is not _A:A._footer_env.text=[(B,f"Env: {E} ")]
|
|
@@ -72,66 +73,77 @@ class LiveChatUI:
|
|
|
72
73
|
def B(event):
|
|
73
74
|
if A.cancel_event:A.cancel_event.set()
|
|
74
75
|
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
|
-
|
|
76
|
+
D='light_steel_blue';C=context;B=text
|
|
77
|
+
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()
|
|
78
|
+
if B.strip()in['quit','exit','q']:get_app().exit();return
|
|
79
|
+
if B.strip()in['/clear','clear']:A.clear();return
|
|
80
|
+
A.spinner.start();A.b('ā user',f"ā {B}",style='light_salmon3');await asyncio.sleep(.05)
|
|
81
|
+
if B.strip()in['/commands']and A.instruction_manager:
|
|
82
|
+
E=[]
|
|
83
|
+
for F in A.instruction_manager.list_instructions():E.append(f"/{F.name}: - {F.settings[_D]}")
|
|
84
|
+
K='\n'.join(E);A.b('ā bot',K,style=D,markdown=_B);return
|
|
85
|
+
if A.instruction_manager:G=A.instruction_manager.parse(B);H,I=G['executed_instruction'],G['message'];B=f"""
|
|
86
|
+
[注ę]: ę§č”ēØę·čÆ·ę±åæ
é”»äø„ę ¼éµå¾Ŗå¦äøåå:
|
|
87
|
+
{H}
|
|
88
|
+
|
|
89
|
+
ēØę·čÆ·ę±:
|
|
90
|
+
{I}"""if H else I
|
|
91
|
+
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
|
|
92
|
+
def b(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
93
|
async def _stream_generate(A,prompt,context=_A):
|
|
82
|
-
B=A.agent.astream({
|
|
94
|
+
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
95
|
async for C in astream_handler(B,interrupt_tools=A.interrupt_tools,tool_mode=A.toolcall_mode):
|
|
84
96
|
if A.cancel_event and A.cancel_event.is_set():A.cancel_event.clear();A.cancel_event=_A;return
|
|
85
97
|
yield C
|
|
86
98
|
async def _resume_generate(A,interrupt_id,decisions,context=_A):
|
|
87
|
-
B=A.agent.astream(Command(resume={interrupt_id:{'decisions':decisions}}),config={
|
|
99
|
+
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
100
|
async for C in astream_handler(B,interrupt_tools=A.interrupt_tools,tool_mode=A.toolcall_mode):
|
|
89
101
|
if A.cancel_event and A.cancel_event.is_set():A.cancel_event.clear();A.cancel_event=_A
|
|
90
102
|
yield C
|
|
91
103
|
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(
|
|
104
|
+
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';Q='args';P='name';I='type';G='content';A=items;R,U='','';t=A is not _A
|
|
105
|
+
if A is _A:D.log_control.append_text(render_panel(a,'',b,c))
|
|
94
106
|
A=A if A else[]
|
|
95
107
|
async for B in stream:
|
|
96
|
-
if B[I]==
|
|
97
|
-
if len(A)>0 and A[-1][1]==
|
|
98
|
-
else:U=B[G];J=markdown_to_wrapped_text(U);A.append([J,
|
|
99
|
-
elif B[I]==
|
|
100
|
-
if len(A)>0 and A[-1][1]==
|
|
101
|
-
else:
|
|
102
|
-
elif B[I]=='token_usage':
|
|
108
|
+
if B[I]==e:
|
|
109
|
+
if len(A)>0 and A[-1][1]==e:U+=B[G];J=markdown_to_wrapped_text(U);A[-1][0]=J
|
|
110
|
+
else:U=B[G];J=markdown_to_wrapped_text(U);A.append([J,e,_A,B,[]])
|
|
111
|
+
elif B[I]==f:
|
|
112
|
+
if len(A)>0 and A[-1][1]==f:R+=B[G];J=markdown_to_wrapped_text(f"{R}");A[-1][0]=J
|
|
113
|
+
else:R=B[G];J=markdown_to_wrapped_text(f"{R}");A.append([J,f,_A,B,[]])
|
|
114
|
+
elif B[I]=='token_usage':u=B['input_toks'];v=B['output_toks'];n=B['total_toks'];D.token_count=n
|
|
103
115
|
elif B[I]==Y:
|
|
104
|
-
V=B[
|
|
116
|
+
V=B[P];W=B[Q];H=B['id'];K=B[l]
|
|
105
117
|
if K is _A:F=display_tool_call(V,W,[]);A.append([F,Y,H,B,[]]);A.append([Text('',''),'margin',_A,_A,[]])
|
|
106
118
|
else:
|
|
107
119
|
C=index_(A,lambda x:x[2]==K and x[1]==Y)
|
|
108
120
|
if C is _A:continue
|
|
109
|
-
|
|
110
|
-
elif B[I]==
|
|
111
|
-
V=B[
|
|
121
|
+
E=A[C];S=E[3][P];T=E[3][Q];A[C][-1].append([_A,Y,H,B,[]]);F=display_tool_call(S,T,A[C][-1]);A[C][0]=F
|
|
122
|
+
elif B[I]==g:
|
|
123
|
+
V=B[P];H=B['id'];K=B[l];X=B[Z]
|
|
112
124
|
if X==Z:
|
|
113
|
-
if K is _A:
|
|
125
|
+
if K is _A:O=B[G];L=index_(A,lambda x:x[2]==H);o=A[L][3];W=o[Q];F=display_tool_result(V,W,O,A[L][-1]);A[L]=[F,g,H,B,A[L][-1]]
|
|
114
126
|
else:
|
|
115
127
|
C=index_(A,lambda x:x[2]==K)
|
|
116
128
|
if C is _A:continue
|
|
117
|
-
E=A[C];
|
|
129
|
+
E=A[C];S=E[3][P];T=E[3][Q];M=index_(E[-1],lambda x:x[2]==H)
|
|
118
130
|
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(
|
|
131
|
+
N=E[-1][M];N[3][Z]=X;N[3][G]=B[G];A[C][-1][M]=N;O='';F=display_tool_result(S,T,O,A[C][-1]);A[C][0]=F
|
|
120
132
|
elif X=='error':
|
|
121
|
-
if K is _A:
|
|
133
|
+
if K is _A:O=B[G];F=display_tool_error(V,W,O,A[L][-1]);A[L]=[F,g,H,B,A[L][-1]]
|
|
122
134
|
else:
|
|
123
135
|
C=index_(A,lambda x:x[2]==K)
|
|
124
136
|
if C is _A:continue
|
|
125
|
-
E=A[C];
|
|
137
|
+
E=A[C];S=E[3][P];T=E[3][Q];M=index_(E[-1],lambda x:x[2]==H)
|
|
126
138
|
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(
|
|
139
|
+
N=E[-1][M];N[Z]=X;N[G]=B[G];A[C][-1][M]=N;F=display_tool_error(S,T,O,A[C][-1]);A[C][0]=F
|
|
128
140
|
elif B[I]=='done':0
|
|
129
141
|
elif B[I]=='interrupt':
|
|
130
|
-
D.spinner.stop();
|
|
131
|
-
for
|
|
132
|
-
D.spinner.start();await D._handle_stream(
|
|
133
|
-
|
|
134
|
-
return
|
|
142
|
+
D.spinner.stop();j=[];p=B['interrupt_id']
|
|
143
|
+
for d in B[m][m]['action_requests']:w=d[P];x=d[Q];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({I:k})
|
|
144
|
+
D.spinner.start();await D._handle_stream(a,D._resume_generate(p,j,i),style=b,markdown=c,items=A,context=i);break
|
|
145
|
+
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)
|
|
146
|
+
return R
|
|
135
147
|
async def _handle_human_interrupt(A,message,options):
|
|
136
148
|
E=asyncio.get_event_loop();C=E.create_future();D=A.app.key_bindings
|
|
137
149
|
def F(index):
|
|
@@ -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.p();A.list_container=HSplit(A.rows,padding=0);A.markdown=A.
|
|
23
|
-
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.p();A.list_container=HSplit(A.rows,padding=0);A.markdown=A.r(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.q()
|
|
23
|
+
def r(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
24
|
def p(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
|
|
29
|
-
def
|
|
28
|
+
def t(A):A.rows=A.p();A.list_container.children=A.rows;get_app().invalidate()
|
|
29
|
+
def q(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.t()
|
|
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.t()
|
|
36
36
|
@A.kb.add('enter')
|
|
37
37
|
def D(event):A.callback(A.selected_index)
|
|
38
38
|
async def demo():
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
_E='agentTypes'
|
|
2
|
+
_D='skills'
|
|
3
|
+
_C='workdir'
|
|
4
|
+
_B='providerDisplayName'
|
|
5
|
+
_A='model'
|
|
6
|
+
from rich.console import Console
|
|
7
|
+
from rich.panel import Panel
|
|
8
|
+
from rich.layout import Layout
|
|
9
|
+
from rich.text import Text
|
|
10
|
+
from rich.align import Align
|
|
11
|
+
from rich.box import ROUNDED
|
|
12
|
+
import os
|
|
13
|
+
PRODUCT_NAME='MyAgent'
|
|
14
|
+
PRODUCT_VERSION='1.0.0'
|
|
15
|
+
ASCII_LOGO=[' _____ _ ',' |_ _| __ _ ___| |_ ___ _ __ '," | || '__| |/ _ \\ __/ _ \\| '__|",' | || | | | __/ || (_) | | ',' |_||_| |_|\\___|\\__\\___/|_| ']
|
|
16
|
+
def banner_view(config):
|
|
17
|
+
J='bold';I='right';G='bold yellow';F='left';B='dim';A=config;D=Console();K=os.get_terminal_size().columns or 80
|
|
18
|
+
if K<20:D.print(f"[bold]{PRODUCT_NAME} v{PRODUCT_VERSION}[/bold]");D.print(f"[dim]{A[_B]} Ā· {A[_A]}[/dim]");return
|
|
19
|
+
C=Layout();C.split_row(Layout(name=F,ratio=1),Layout(name=I,ratio=1));L=A[_C].split('/')[-1]or'workspace';H=A[_D];M=', '.join(H[:3])if H else'none';E=[Text('Welcome back!',style=J),'']
|
|
20
|
+
for N in ASCII_LOGO:E.append(Text(N,style='bright_cyan'))
|
|
21
|
+
E.extend(['',Text(f"{A[_A]}",style=B),Text(f"~/{L}",style=B)]);C[F].update(Align.left('\n'.join(map(str,E))));O=[Text('Tips for getting started',style=G),Text('č¾å
„ę¶ęÆå¼å§åƹčÆ',style=B),Text("ä½æēØ 'exit' éåŗļ¼Ctrl+C äøę",style=B),'',Text('Configuration',style=G),Text(f"Provider: {A[_B]}",style=B),Text(f"Model: {A[_A][:30]}",style=B),Text(f"Skills: {M}",style=B),'',Text('Agent Types',style=G),Text(' Ā· '.join(A[_E]),style=B)];C[I].update(Align.left('\n'.join(map(str,O))));P=Text(f" {PRODUCT_NAME} v{PRODUCT_VERSION}",style=J);Q=Panel(C,title=P,title_align=F,border_style='blue',box=ROUNDED,padding=(0,1));D.print(Q)
|
|
22
|
+
if __name__=='__main__':test_config={_C:'/user/projects/ai-agent',_D:['code','chat','search','debug'],_B:'OpenAI',_A:'gpt-4o-mini',_E:['chat','code','tool']};banner_view(test_config)
|
|
@@ -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=h(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=[]):
|
|
@@ -36,17 +36,17 @@ def display_tool_result(tool_name,args=_E,result=_E,events=[]):
|
|
|
36
36
|
if A is _E:A={}
|
|
37
37
|
H=format_tool_compact(G,A);C=G.lower()
|
|
38
38
|
try:
|
|
39
|
-
if C==_K and isinstance(A,dict):B=
|
|
40
|
-
elif C==_L and isinstance(A,dict):B=
|
|
41
|
-
elif C in[_M]and isinstance(A,dict):B=
|
|
42
|
-
elif C==_H and isinstance(A,dict):B=
|
|
39
|
+
if C==_K and isinstance(A,dict):B=f(A)
|
|
40
|
+
elif C==_L and isinstance(A,dict):B=f(A)
|
|
41
|
+
elif C in[_M]and isinstance(A,dict):B=f(A)
|
|
42
|
+
elif C==_H and isinstance(A,dict):B=o(A,D)
|
|
43
43
|
elif C==_N and isinstance(A,dict):B=m(A,D)
|
|
44
|
-
elif C==_O and isinstance(A,dict):B=
|
|
45
|
-
elif C==_P and isinstance(A,dict):B=
|
|
46
|
-
else:B=
|
|
44
|
+
elif C==_O and isinstance(A,dict):B=n(A,D)
|
|
45
|
+
elif C==_P and isinstance(A,dict):B=l(A,D)
|
|
46
|
+
else:B=k(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 h(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 j(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'])[:
|
|
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'])[:100];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 j(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=''
|
|
@@ -136,7 +136,7 @@ def n(arguments):
|
|
|
136
136
|
E=recognize_language(A)
|
|
137
137
|
if E:G=f"```\n{E}\n{B}\n```";return render_content_with_line_limit(G,'',100)
|
|
138
138
|
else:return render_content_with_line_limit(B,'',100)
|
|
139
|
-
def
|
|
139
|
+
def f(arguments):
|
|
140
140
|
B=arguments.get(_F,'');C=''
|
|
141
141
|
if os.path.exists(B):C=open(B,'r').read()
|
|
142
142
|
E=C.split(_A);F=len(E);A=50
|
|
@@ -145,7 +145,7 @@ def k(arguments):
|
|
|
145
145
|
H=recognize_language(B)
|
|
146
146
|
if H:J=f"```{H}\n{D}\n```";return render_content_with_line_limit(J,'',-1)
|
|
147
147
|
else:return render_content_with_line_limit(D,'',-1)
|
|
148
|
-
def
|
|
148
|
+
def i(arguments,result):
|
|
149
149
|
C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
|
|
150
150
|
for(H,A)in enumerate(G):
|
|
151
151
|
I=''if H==0 else''
|
|
@@ -154,7 +154,7 @@ def l(arguments,result):
|
|
|
154
154
|
E=F-D
|
|
155
155
|
if E>0:B.append(f" ... and {E} more lines")
|
|
156
156
|
return Text(_A.join(B),style=_G)
|
|
157
|
-
def
|
|
157
|
+
def o(arguments,result):
|
|
158
158
|
C=result.strip().split(_A);F=len(C);B=[];D=10;G=C[:D]
|
|
159
159
|
for(H,A)in enumerate(G):
|
|
160
160
|
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 n(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 l(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 k(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
|