@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
package/dist/python-src/entry.py
CHANGED
|
@@ -5,11 +5,80 @@
|
|
|
5
5
|
# if __name__ == "__main__":
|
|
6
6
|
# main()
|
|
7
7
|
|
|
8
|
+
|
|
9
|
+
# # ===================== 强制修复 Git Bash 报错:NoConsoleScreenBufferError =====================
|
|
10
|
+
# import os
|
|
11
|
+
# import sys
|
|
12
|
+
|
|
13
|
+
# # 🔥 核心:强制让 prompt_toolkit 使用兼容模式,彻底关闭 Windows 控制台检测
|
|
14
|
+
# os.environ["PROMPT_TOOLKIT_NO_WIN32"] = "1"
|
|
15
|
+
# os.environ["PROMPT_TOOLKIT_BASIC_OUTPUT"] = "1"
|
|
16
|
+
# os.environ["PROMPT_TOOLKIT_FORCE_VT100"] = "1"
|
|
17
|
+
|
|
18
|
+
# # 🔥 强制设置终端类型,让程序认为是 Linux 终端
|
|
19
|
+
# if sys.platform == "win32":
|
|
20
|
+
# os.environ["TERM"] = "xterm-256color"
|
|
21
|
+
|
|
22
|
+
# # ===================== 下面才是你原来的代码 =====================
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
import warnings
|
|
26
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
27
|
+
warnings.filterwarnings("ignore", message="Pydantic serializer warnings")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
import typer
|
|
31
|
+
import asyncio
|
|
32
|
+
|
|
33
|
+
|
|
8
34
|
from main import (
|
|
9
35
|
agent_ui,
|
|
10
36
|
asingle_agent,
|
|
37
|
+
team_main,
|
|
38
|
+
run_once,
|
|
39
|
+
teminal_chat
|
|
11
40
|
)
|
|
12
41
|
|
|
42
|
+
app = typer.Typer()
|
|
43
|
+
interact_app = typer.Typer()
|
|
44
|
+
app.add_typer(interact_app)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@app.callback(invoke_without_command=True, no_args_is_help=False)
|
|
48
|
+
def root(
|
|
49
|
+
ctx: typer.Context,
|
|
50
|
+
prompt: str = typer.Option(None, "-p", "--prompt", help="用户输入请求内容"),
|
|
51
|
+
verbose: bool = typer.Option(False, "-v", "--verbose", help="显示agent执行详细过程"),
|
|
52
|
+
mode: str = typer.Option("team", "-m", "--mode", help="运行模式,single或team"),
|
|
53
|
+
):
|
|
54
|
+
if ctx.invoked_subcommand is None:
|
|
55
|
+
if not prompt:
|
|
56
|
+
if mode == "single":
|
|
57
|
+
asyncio.run(asingle_agent())
|
|
58
|
+
elif mode == "team":
|
|
59
|
+
asyncio.run(team_main())
|
|
60
|
+
|
|
61
|
+
# 同步环境执行异步任务
|
|
62
|
+
asyncio.run(run_once(prompt, verbose))
|
|
63
|
+
# typer.echo(result)
|
|
64
|
+
# raise typer.Exit()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@interact_app.command("interact")
|
|
68
|
+
def interact_mode(
|
|
69
|
+
verbose: bool = typer.Option(False, "-v", "--verbose", help="显示agent执行详细过程"),
|
|
70
|
+
):
|
|
71
|
+
# 执行交互模式
|
|
72
|
+
asyncio.run(teminal_chat(verbose))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
13
76
|
if __name__ == "__main__":
|
|
14
|
-
|
|
15
|
-
asyncio
|
|
77
|
+
app()
|
|
78
|
+
# import asyncio
|
|
79
|
+
|
|
80
|
+
# try:
|
|
81
|
+
# # asyncio.run(asingle_agent())
|
|
82
|
+
# asyncio.run(team_main())
|
|
83
|
+
# except Exception as e:
|
|
84
|
+
# pass
|
package/dist/python-src/main.py
CHANGED
|
@@ -19,6 +19,12 @@ _ = load_dotenv(find_dotenv())
|
|
|
19
19
|
from langchain_core.messages import AIMessageChunk
|
|
20
20
|
|
|
21
21
|
|
|
22
|
+
import warnings
|
|
23
|
+
warnings.filterwarnings("ignore", category=DeprecationWarning)
|
|
24
|
+
warnings.filterwarnings("ignore", message="Pydantic serializer warnings")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
22
28
|
|
|
23
29
|
# # ========== 关键修改1:配置logging,让INFO级别日志能输出 ==========
|
|
24
30
|
# import logging
|
|
@@ -214,15 +220,446 @@ async def asingle_agent():
|
|
|
214
220
|
# sandbox=None
|
|
215
221
|
)
|
|
216
222
|
|
|
223
|
+
tui = LiveChatUI(
|
|
224
|
+
agent=agent,
|
|
225
|
+
saver=saver,
|
|
226
|
+
workspace=WORKSPACE,
|
|
227
|
+
context=context,
|
|
228
|
+
interrupt_tools=[
|
|
229
|
+
"bash",
|
|
230
|
+
"read_file",
|
|
231
|
+
"write_file",
|
|
232
|
+
"glob",
|
|
233
|
+
"grep",
|
|
234
|
+
"edit",
|
|
235
|
+
"list_dir",
|
|
236
|
+
"web_search",
|
|
237
|
+
"web_fetch"
|
|
238
|
+
],
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
await tui.run_async()
|
|
217
242
|
|
|
218
243
|
|
|
219
|
-
|
|
244
|
+
async def team_main():
|
|
245
|
+
""" 加载开发团队 """
|
|
246
|
+
from dataclasses import dataclass, field
|
|
247
|
+
from pathlib import Path
|
|
220
248
|
|
|
221
|
-
|
|
249
|
+
from src.core.deepagents import create_deep_agent, get_default_model
|
|
250
|
+
from src.managers.manager_context import ContextManager
|
|
251
|
+
from src.utils.prompt import apply_template, apply_prompt
|
|
252
|
+
from src.managers.sandbox import Container
|
|
253
|
+
from src.prompts.prompts import leader
|
|
254
|
+
|
|
255
|
+
from src.tools.tools import (
|
|
256
|
+
SkillAgentContext,
|
|
257
|
+
shell,
|
|
258
|
+
bash,
|
|
259
|
+
write_file,
|
|
260
|
+
read_file,
|
|
261
|
+
list_dir,
|
|
262
|
+
glob,
|
|
263
|
+
grep,
|
|
264
|
+
edit
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
from src.tools.web import (
|
|
268
|
+
web_search,
|
|
269
|
+
web_fetch
|
|
270
|
+
)
|
|
271
|
+
|
|
272
|
+
from langgraph.checkpoint.memory import MemorySaver
|
|
273
|
+
from langchain_core.tools import BaseTool
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
def _prepare(workspace, run_mode, session_id):
|
|
277
|
+
saver = MemorySaver()
|
|
278
|
+
|
|
279
|
+
# 1. 构建上下文管理器
|
|
280
|
+
context_manager = ContextManager(
|
|
281
|
+
dockerfile_path=os.path.join(os.getcwd(), "sources", "docker", "Dockerfile.sandbox"),
|
|
282
|
+
mode=run_mode
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
context_manager.create_environment(
|
|
286
|
+
session_id=session_id,
|
|
287
|
+
workspace_path=workspace,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
# 2. 指令管理器
|
|
291
|
+
instruction_manager = context_manager.get_instruction_manager(
|
|
292
|
+
session_id=session_id
|
|
293
|
+
)
|
|
294
|
+
|
|
295
|
+
# 3. 代理管理器
|
|
296
|
+
agent_manager = context_manager.get_agent_manager(
|
|
297
|
+
session_id=session_id
|
|
298
|
+
)
|
|
299
|
+
|
|
300
|
+
# 4. mcp 管理器
|
|
301
|
+
# mcp_manager = context_manager.get_mcp_manager(
|
|
302
|
+
# session_id=session_id
|
|
303
|
+
# )
|
|
304
|
+
|
|
305
|
+
# 5. 沙箱
|
|
306
|
+
sandbox = context_manager.get_container(
|
|
307
|
+
session_id=session_id
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
# 6. 获取配置
|
|
311
|
+
agents_conf = agent_manager.get_all_conf()
|
|
312
|
+
|
|
313
|
+
toolkits = {
|
|
314
|
+
"filetools": [ shell, read_file, write_file, glob, grep, edit, list_dir],
|
|
315
|
+
"web": [web_search, web_fetch]
|
|
316
|
+
} if run_mode == "sandbox" else {
|
|
317
|
+
"filetools": [ bash, read_file, write_file, glob, grep, edit, list_dir],
|
|
318
|
+
"web": [web_search, web_fetch]
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
context = SkillAgentContext(
|
|
322
|
+
working_directory=workspace,
|
|
323
|
+
# skill_loader=None,
|
|
324
|
+
sandbox=sandbox
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
return agents_conf, toolkits, context, saver, instruction_manager
|
|
328
|
+
|
|
329
|
+
def _build_team(agents_conf: Dict[str, Any], domain: str, llm: ChatOpenAI, toolkits: Dict[str, List[BaseTool]], workspace: str, saver=None, store=None, recursion_limit=1000):
|
|
330
|
+
""" """
|
|
331
|
+
team_conf = agents_conf[domain]
|
|
332
|
+
|
|
333
|
+
# for mname, mconf in team_conf['members'].items():
|
|
334
|
+
# print(f"member_name: {mname}, member: {mconf}")
|
|
335
|
+
|
|
336
|
+
agents = []
|
|
337
|
+
for member_name, member in team_conf["members"].items():
|
|
338
|
+
# print(f"member_name: {member_name}, member: {member}")
|
|
339
|
+
|
|
340
|
+
tools = []
|
|
341
|
+
for tool_name in member["tools"]:
|
|
342
|
+
tools.extend(toolkits.get(tool_name, []))
|
|
343
|
+
|
|
344
|
+
llm_conf = member.get("llm", None)
|
|
345
|
+
model = ChatOpenAI(**llm_conf) if llm_conf else get_default_model(streaming=False)
|
|
346
|
+
|
|
347
|
+
agent = {
|
|
348
|
+
"name": member_name,
|
|
349
|
+
"description": member["description"],
|
|
350
|
+
"system_prompt": apply_template(
|
|
351
|
+
agents_config=agents_conf,
|
|
352
|
+
domain=domain,
|
|
353
|
+
prompt_name=member_name,
|
|
354
|
+
WORKSPACE=workspace
|
|
355
|
+
),
|
|
356
|
+
"context_schema": SkillAgentContext,
|
|
357
|
+
"tools": tools,
|
|
358
|
+
"model": model
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
agents.append(agent)
|
|
362
|
+
|
|
363
|
+
tools = []
|
|
364
|
+
for tool_name in ["filetools", "web"]:
|
|
365
|
+
tools.extend([tool for tool in toolkits.get(tool_name, [])])
|
|
366
|
+
|
|
367
|
+
team = create_deep_agent(
|
|
368
|
+
model=llm,
|
|
369
|
+
subagents=agents,
|
|
370
|
+
tools=tools,
|
|
371
|
+
context_schema=SkillAgentContext,
|
|
372
|
+
# system_prompt=apply_template(
|
|
373
|
+
# agents_config=agents_conf,
|
|
374
|
+
# domain="default",
|
|
375
|
+
# prompt_name="leader_",
|
|
376
|
+
# WORKSPACE=workspace
|
|
377
|
+
# ),
|
|
378
|
+
system_prompt=apply_prompt(leader, WORKSPACE=workspace),
|
|
379
|
+
checkpointer=saver
|
|
380
|
+
).with_config({"recursion_limit": recursion_limit})
|
|
381
|
+
|
|
382
|
+
return team
|
|
383
|
+
|
|
384
|
+
# workspace = os.path.join(os.getcwd(), "workspace")
|
|
385
|
+
workspace = os.getcwd()
|
|
386
|
+
run_mode = "local"
|
|
387
|
+
session_id = "1"
|
|
388
|
+
|
|
389
|
+
# agents_conf, toolkits, context, saver, instruction_manager
|
|
390
|
+
agents_config, toolkits, context, saver, instruction_manager = _prepare(workspace, run_mode, session_id)
|
|
391
|
+
agent = _build_team(
|
|
392
|
+
agents_conf=agents_config,
|
|
393
|
+
domain="coding",
|
|
394
|
+
llm=llm,
|
|
395
|
+
toolkits=toolkits,
|
|
396
|
+
workspace=workspace,
|
|
397
|
+
saver=saver,
|
|
398
|
+
store=None,
|
|
399
|
+
recursion_limit=1000
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
ui = LiveChatUI(agent=agent, saver=saver, workspace=workspace, context=context, instruction_manager=instruction_manager)
|
|
403
|
+
|
|
404
|
+
await ui.run_async()
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def build_team():
|
|
408
|
+
from dataclasses import dataclass, field
|
|
409
|
+
from pathlib import Path
|
|
410
|
+
|
|
411
|
+
from src.core.deepagents import create_deep_agent, get_default_model
|
|
412
|
+
from src.managers.manager_context import ContextManager
|
|
413
|
+
from src.utils.prompt import apply_template, apply_prompt
|
|
414
|
+
from src.managers.sandbox import Container
|
|
415
|
+
from src.prompts.prompts import leader
|
|
416
|
+
from src.tools.tools import (
|
|
417
|
+
SkillAgentContext,
|
|
418
|
+
shell,
|
|
419
|
+
bash,
|
|
420
|
+
write_file,
|
|
421
|
+
read_file,
|
|
422
|
+
list_dir,
|
|
423
|
+
glob,
|
|
424
|
+
grep,
|
|
425
|
+
edit
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
from src.tools.web import (
|
|
429
|
+
web_search,
|
|
430
|
+
web_fetch
|
|
431
|
+
)
|
|
432
|
+
from src.middlewares.dynamic_content import DynamicContentMiddleware
|
|
433
|
+
|
|
434
|
+
from langgraph.checkpoint.memory import MemorySaver
|
|
435
|
+
from langchain_core.tools import BaseTool
|
|
222
436
|
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
def _prepare(workspace, run_mode, session_id):
|
|
441
|
+
saver = MemorySaver()
|
|
442
|
+
|
|
443
|
+
# 1. 构建上下文管理器
|
|
444
|
+
context_manager = ContextManager(
|
|
445
|
+
dockerfile_path=os.path.join(os.getcwd(), "sources", "docker", "Dockerfile.sandbox"),
|
|
446
|
+
mode=run_mode
|
|
447
|
+
)
|
|
448
|
+
|
|
449
|
+
context_manager.create_environment(
|
|
450
|
+
session_id=session_id,
|
|
451
|
+
workspace_path=workspace,
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
# 2. 指令管理器
|
|
455
|
+
instruction_manager = context_manager.get_instruction_manager(
|
|
456
|
+
session_id=session_id
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
# 3. 代理管理器
|
|
460
|
+
agent_manager = context_manager.get_agent_manager(
|
|
461
|
+
session_id=session_id
|
|
462
|
+
)
|
|
463
|
+
|
|
464
|
+
# 4. mcp 管理器
|
|
465
|
+
# mcp_manager = context_manager.get_mcp_manager(
|
|
466
|
+
# session_id=session_id
|
|
467
|
+
# )
|
|
468
|
+
|
|
469
|
+
# 5. 沙箱
|
|
470
|
+
sandbox = context_manager.get_container(
|
|
471
|
+
session_id=session_id
|
|
472
|
+
)
|
|
473
|
+
|
|
474
|
+
# 6. 获取配置
|
|
475
|
+
agents_conf = agent_manager.get_all_conf()
|
|
476
|
+
|
|
477
|
+
toolkits = {
|
|
478
|
+
"filetools": [ shell, read_file, write_file, glob, grep, edit, list_dir],
|
|
479
|
+
"web": [web_search, web_fetch]
|
|
480
|
+
} if run_mode == "sandbox" else {
|
|
481
|
+
"filetools": [ bash, read_file, write_file, glob, grep, edit, list_dir],
|
|
482
|
+
"web": [web_search, web_fetch]
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
context = SkillAgentContext(
|
|
486
|
+
working_directory=workspace,
|
|
487
|
+
# skill_loader=None,
|
|
488
|
+
sandbox=sandbox
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
return agents_conf, toolkits, context, saver, instruction_manager
|
|
492
|
+
|
|
493
|
+
def _build_team(agents_conf: Dict[str, Any], domain: str, llm: ChatOpenAI, toolkits: Dict[str, List[BaseTool]], workspace: str, saver=None, store=None, recursion_limit=1000):
|
|
494
|
+
""" """
|
|
495
|
+
team_conf = agents_conf.setdefault(domain, {"members":{}})
|
|
496
|
+
|
|
497
|
+
# for mname, mconf in team_conf['members'].items():
|
|
498
|
+
# print(f"member_name: {mname}, member: {mconf}")
|
|
499
|
+
|
|
500
|
+
agents = []
|
|
501
|
+
for member_name, member in team_conf["members"].items():
|
|
502
|
+
# print(f"member_name: {member_name}, member: {member}")
|
|
503
|
+
|
|
504
|
+
tools = []
|
|
505
|
+
for tool_name in member["tools"]:
|
|
506
|
+
tools.extend(toolkits.get(tool_name, []))
|
|
507
|
+
|
|
508
|
+
llm_conf = member.get("llm", None)
|
|
509
|
+
model = ChatOpenAI(**llm_conf) if llm_conf else get_default_model(streaming=False)
|
|
510
|
+
|
|
511
|
+
agent = {
|
|
512
|
+
"name": member_name,
|
|
513
|
+
"description": member["description"],
|
|
514
|
+
"system_prompt": apply_template(
|
|
515
|
+
agents_config=agents_conf,
|
|
516
|
+
domain=domain,
|
|
517
|
+
prompt_name=member_name,
|
|
518
|
+
WORKSPACE=workspace
|
|
519
|
+
),
|
|
520
|
+
"context_schema": SkillAgentContext,
|
|
521
|
+
"tools": tools,
|
|
522
|
+
"model": model
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
agents.append(agent)
|
|
526
|
+
|
|
527
|
+
tools = []
|
|
528
|
+
for tool_name in ["filetools", "web"]:
|
|
529
|
+
tools.extend([tool for tool in toolkits.get(tool_name, [])])
|
|
530
|
+
|
|
531
|
+
team = create_deep_agent(
|
|
532
|
+
model=llm,
|
|
533
|
+
subagents=agents,
|
|
534
|
+
tools=tools,
|
|
535
|
+
context_schema=SkillAgentContext,
|
|
536
|
+
# system_prompt=apply_template(
|
|
537
|
+
# agents_config=agents_conf,
|
|
538
|
+
# domain="default",
|
|
539
|
+
# prompt_name="leader_",
|
|
540
|
+
# WORKSPACE=workspace
|
|
541
|
+
# ),
|
|
542
|
+
middleware=[
|
|
543
|
+
DynamicContentMiddleware(),
|
|
544
|
+
],
|
|
545
|
+
system_prompt=apply_prompt(leader, WORKSPACE=workspace),
|
|
546
|
+
checkpointer=saver
|
|
547
|
+
).with_config({"recursion_limit": recursion_limit})
|
|
548
|
+
|
|
549
|
+
return team
|
|
550
|
+
|
|
551
|
+
# workspace = os.path.join(os.getcwd(), "workspace")
|
|
552
|
+
workspace = os.getcwd()
|
|
553
|
+
run_mode = "local"
|
|
554
|
+
session_id = "1"
|
|
555
|
+
|
|
556
|
+
# agents_conf, toolkits, context, saver, instruction_manager
|
|
557
|
+
agents_config, toolkits, context, saver, instruction_manager = _prepare(workspace, run_mode, session_id)
|
|
558
|
+
agent = _build_team(
|
|
559
|
+
agents_conf=agents_config,
|
|
560
|
+
domain="coding",
|
|
561
|
+
llm=llm,
|
|
562
|
+
toolkits=toolkits,
|
|
563
|
+
workspace=workspace,
|
|
564
|
+
saver=saver,
|
|
565
|
+
store=None,
|
|
566
|
+
recursion_limit=1000
|
|
567
|
+
)
|
|
568
|
+
|
|
569
|
+
return agent, context, instruction_manager
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
async def teminal_chat(verbose=True):
|
|
573
|
+
""" """
|
|
574
|
+
from langchain_core.messages import HumanMessage
|
|
575
|
+
from src.stream.handler import ainput, anormal_handler
|
|
576
|
+
|
|
577
|
+
agent, context, instruction_manager = build_team()
|
|
578
|
+
|
|
579
|
+
try:
|
|
580
|
+
while True:
|
|
581
|
+
query = await ainput("user>")
|
|
582
|
+
|
|
583
|
+
if query == "/comands":
|
|
584
|
+
for instruction in instruction_manager.list_instructions():
|
|
585
|
+
# print(instruction)
|
|
586
|
+
print(f"command: {instruction.name}, description: {instruction.description}")
|
|
587
|
+
continue
|
|
588
|
+
|
|
589
|
+
instruction_result = instruction_manager.parse(query)
|
|
590
|
+
executed_instruction, message = instruction_result["executed_instruction"], instruction_result['message']
|
|
591
|
+
|
|
592
|
+
new_query = f"\n [注意]: 执行用户请求必须严格遵循如下准则:\n{executed_instruction}\n\n 用户请求:\n{message}" if executed_instruction else message
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
print(f"【new_query】:\n {new_query}")
|
|
596
|
+
|
|
597
|
+
stream = agent.astream(
|
|
598
|
+
{
|
|
599
|
+
"messages":[HumanMessage(content=new_query)]
|
|
600
|
+
},
|
|
601
|
+
config = {"configurable": {"thread_id": 1}},
|
|
602
|
+
stream_mode=["updates", "custom"],
|
|
603
|
+
context=context
|
|
604
|
+
) # .with_config({"recursion_limit": 1000})
|
|
605
|
+
|
|
606
|
+
await anormal_handler(stream, detail=verbose)
|
|
607
|
+
|
|
608
|
+
except Exception as e:
|
|
609
|
+
import traceback
|
|
610
|
+
traceback.print_exc()
|
|
611
|
+
finally:
|
|
612
|
+
pass
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
async def run_once(prompt:str = None, verbose: bool=True):
|
|
616
|
+
from langchain_core.messages import HumanMessage
|
|
617
|
+
from src.stream.handler import ainput, anormal_handler
|
|
618
|
+
|
|
619
|
+
agent, context, instruction_manager = build_team()
|
|
620
|
+
|
|
621
|
+
query = prompt
|
|
622
|
+
|
|
623
|
+
try:
|
|
624
|
+
if query == "/comands":
|
|
625
|
+
for instruction in instruction_manager.list_instructions():
|
|
626
|
+
# print(instruction)
|
|
627
|
+
print(f"command: {instruction.name}, description: {instruction.description}")
|
|
628
|
+
|
|
629
|
+
instruction_result = instruction_manager.parse(query)
|
|
630
|
+
executed_instruction, message = instruction_result["executed_instruction"], instruction_result['message']
|
|
631
|
+
|
|
632
|
+
new_query = f"\n [注意]: 执行用户请求必须严格遵循如下准则:\n{executed_instruction}\n\n 用户请求:\n{message}" if executed_instruction else message
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
if verbose:
|
|
636
|
+
print(f"user> {new_query}")
|
|
637
|
+
|
|
638
|
+
stream = agent.astream(
|
|
639
|
+
{
|
|
640
|
+
"messages":[HumanMessage(content=new_query)]
|
|
641
|
+
},
|
|
642
|
+
config = {"configurable": {"thread_id": 1}},
|
|
643
|
+
stream_mode=["updates", "custom"],
|
|
644
|
+
context=context
|
|
645
|
+
) # .with_config({"recursion_limit": 1000})
|
|
646
|
+
|
|
647
|
+
await anormal_handler(stream, detail=verbose)
|
|
648
|
+
|
|
649
|
+
except Exception as e:
|
|
650
|
+
import traceback
|
|
651
|
+
traceback.print_exc()
|
|
652
|
+
|
|
653
|
+
finally:
|
|
654
|
+
pass
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
|
|
223
659
|
|
|
224
660
|
if __name__ == "__main__":
|
|
225
|
-
pass
|
|
661
|
+
# pass
|
|
662
|
+
asyncio.run(teminal_chat())
|
|
226
663
|
# asyncio.run(agent_ui())
|
|
227
664
|
# asyncio.run(team_main())
|
|
228
665
|
# asyncio.run(asingle_agent())
|
|
@@ -23,7 +23,6 @@ dependencies = [
|
|
|
23
23
|
"croniter>=6.0.0",
|
|
24
24
|
"apscheduler>=3.11.2",
|
|
25
25
|
"whatthepatch>=1.0.7",
|
|
26
|
-
"ddgs>=9.10.0",
|
|
27
26
|
"requests>=2.32.5",
|
|
28
27
|
"beautifulsoup4>=4.14.3",
|
|
29
28
|
"langchain-dashscope>=0.1.8",
|
|
@@ -32,6 +31,8 @@ dependencies = [
|
|
|
32
31
|
"dashscope>=1.25.12",
|
|
33
32
|
"langchain-core==1.2.13",
|
|
34
33
|
"python-minifier>=3.2.0",
|
|
34
|
+
"ddgs>=9.11.4",
|
|
35
|
+
"typer>=0.24.1",
|
|
35
36
|
]
|
|
36
37
|
|
|
37
38
|
#[project.scripts]
|
|
@@ -56,7 +57,7 @@ skip = [
|
|
|
56
57
|
"resources",
|
|
57
58
|
"_workspace",
|
|
58
59
|
".autodev",
|
|
59
|
-
"tools"
|
|
60
|
+
"tools",
|
|
60
61
|
]
|
|
61
62
|
|
|
62
63
|
exclude = [
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ai-tcode
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Requires-Python: >=3.11
|
|
5
|
+
Requires-Dist: prompt-toolkit>=3.0.43
|
|
6
|
+
Requires-Dist: rich>=13.0.0
|
|
7
|
+
Requires-Dist: pyyaml>=6.0.0
|
|
8
|
+
Requires-Dist: click>=8.0.0
|
|
9
|
+
Requires-Dist: numpy>=1.24.0
|
|
10
|
+
Requires-Dist: python-dateutil>=2.8.0
|
|
11
|
+
Requires-Dist: langchain>=1.0.0
|
|
12
|
+
Requires-Dist: langchain-openai>=1.0.0
|
|
13
|
+
Requires-Dist: langgraph>=1.0.0
|
|
14
|
+
Requires-Dist: pyyaml>=6.0
|
|
15
|
+
Requires-Dist: python-dotenv>=1.0
|
|
16
|
+
Requires-Dist: lark-oapi>=1.5.3
|
|
17
|
+
Requires-Dist: langchain-mcp-adapters>=0.2.1
|
|
18
|
+
Requires-Dist: docker>=7.1.0
|
|
19
|
+
Requires-Dist: croniter>=6.0.0
|
|
20
|
+
Requires-Dist: apscheduler>=3.11.2
|
|
21
|
+
Requires-Dist: whatthepatch>=1.0.7
|
|
22
|
+
Requires-Dist: ddgs>=9.10.0
|
|
23
|
+
Requires-Dist: requests>=2.32.5
|
|
24
|
+
Requires-Dist: beautifulsoup4>=4.14.3
|
|
25
|
+
Requires-Dist: langchain-dashscope>=0.1.8
|
|
26
|
+
Requires-Dist: langchain-alibaba>=0.1.1
|
|
27
|
+
Requires-Dist: langchain-community>=0.4.1
|
|
28
|
+
Requires-Dist: dashscope>=1.25.12
|
|
29
|
+
Requires-Dist: langchain-core==1.2.13
|
|
30
|
+
Requires-Dist: python-minifier>=3.2.0
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/__init__.py
|
|
4
|
+
src/agents/__init__.py
|
|
5
|
+
src/ai_tcode.egg-info/PKG-INFO
|
|
6
|
+
src/ai_tcode.egg-info/SOURCES.txt
|
|
7
|
+
src/ai_tcode.egg-info/dependency_links.txt
|
|
8
|
+
src/ai_tcode.egg-info/requires.txt
|
|
9
|
+
src/ai_tcode.egg-info/top_level.txt
|
|
10
|
+
src/core/__init__.py
|
|
11
|
+
src/core/deepagents.py
|
|
12
|
+
src/core/prompts.py
|
|
13
|
+
src/managers/__init__.py
|
|
14
|
+
src/managers/sandbox.py
|
|
15
|
+
src/middlewares/__init__.py
|
|
16
|
+
src/middlewares/dynamic_prompt.py
|
|
17
|
+
src/middlewares/hitl.py
|
|
18
|
+
src/middlewares/patch_tool_calls.py
|
|
19
|
+
src/middlewares/subagents.py
|
|
20
|
+
src/middlewares/summary.py
|
|
21
|
+
src/stream/__init__.py
|
|
22
|
+
src/stream/emitter.py
|
|
23
|
+
src/stream/file_write_parser.py
|
|
24
|
+
src/stream/formatter.py
|
|
25
|
+
src/stream/handler.py
|
|
26
|
+
src/stream/handler_with_tracker.py
|
|
27
|
+
src/stream/tracker.py
|
|
28
|
+
src/stream/utils.py
|
|
29
|
+
src/tools/__init__.py
|
|
30
|
+
src/tools/security_hook.py
|
|
31
|
+
src/tools/skill_loader.py
|
|
32
|
+
src/tools/tools.py
|
|
33
|
+
src/tools/tools_.py
|
|
34
|
+
src/tools/web.py
|
|
35
|
+
src/tui/chatui.py
|
|
36
|
+
src/tui/config.py
|
|
37
|
+
src/tui/components/__init__.py
|
|
38
|
+
src/tui/components/live_spinner.py
|
|
39
|
+
src/tui/components/tdiff.py
|
|
40
|
+
src/tui/components/tdisplay.py
|
|
41
|
+
src/tui/components/tlist.py
|
|
42
|
+
src/tui/components/tscroll_panel.py
|
|
43
|
+
src/tui/utils/__init__.py
|
|
44
|
+
src/tui/utils/render.py
|
|
45
|
+
src/tui/utils/trender.py
|
|
46
|
+
src/utils/__init__.py
|
|
47
|
+
src/utils/prompt.py
|
|
48
|
+
src/utils/utils.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
prompt-toolkit>=3.0.43
|
|
2
|
+
rich>=13.0.0
|
|
3
|
+
pyyaml>=6.0.0
|
|
4
|
+
click>=8.0.0
|
|
5
|
+
numpy>=1.24.0
|
|
6
|
+
python-dateutil>=2.8.0
|
|
7
|
+
langchain>=1.0.0
|
|
8
|
+
langchain-openai>=1.0.0
|
|
9
|
+
langgraph>=1.0.0
|
|
10
|
+
pyyaml>=6.0
|
|
11
|
+
python-dotenv>=1.0
|
|
12
|
+
lark-oapi>=1.5.3
|
|
13
|
+
langchain-mcp-adapters>=0.2.1
|
|
14
|
+
docker>=7.1.0
|
|
15
|
+
croniter>=6.0.0
|
|
16
|
+
apscheduler>=3.11.2
|
|
17
|
+
whatthepatch>=1.0.7
|
|
18
|
+
ddgs>=9.10.0
|
|
19
|
+
requests>=2.32.5
|
|
20
|
+
beautifulsoup4>=4.14.3
|
|
21
|
+
langchain-dashscope>=0.1.8
|
|
22
|
+
langchain-alibaba>=0.1.1
|
|
23
|
+
langchain-community>=0.4.1
|
|
24
|
+
dashscope>=1.25.12
|
|
25
|
+
langchain-core==1.2.13
|
|
26
|
+
python-minifier>=3.2.0
|
|
@@ -20,7 +20,7 @@ from src.middlewares.hitl import HumanInTheLoopMiddleware
|
|
|
20
20
|
from dotenv import find_dotenv,load_dotenv
|
|
21
21
|
import os
|
|
22
22
|
_=load_dotenv(find_dotenv())
|
|
23
|
-
def get_default_model(streaming=False):return ChatOpenAI(model_name=os.getenv(
|
|
23
|
+
def get_default_model(streaming=False):D='OPENAI_API_KEY';C='OPENAI_API_BASE';B='DEFAULT_MODEL';A=streaming;return ChatOpenAI(model_name=os.getenv(B),base_url=os.getenv(C),api_key=os.getenv(D),streaming=A,model_kwargs={'stream_options':{'include_usage':True}})if A else ChatOpenAI(model_name=os.getenv(B),base_url=os.getenv(C),api_key=os.getenv(D),streaming=A)
|
|
24
24
|
def create_deep_agent(model=_A,tools=_A,*,system_prompt=_A,middleware=(),subagents=_A,response_format=_A,context_schema=_A,checkpointer=_A,store=_A,interrupt_on=_A,debug=False,name=_A,cache=_A,recursion_limit=1000):
|
|
25
25
|
G=subagents;F=middleware;E=system_prompt;D=tools;B=interrupt_on;A=model
|
|
26
26
|
if A is _A:A=get_default_model(streaming=True)
|