Feature/delta team/epic r04 (#7)
CI / test (push) Canceled after 0s

## Summary

epic r04 - begin refactor

## Change Type

- [x] Cowork feature
- [ ] Bug fix
- [ ] Core AI contribution
- [ ] Test / hardening
- [ ] Performance
- [ ] Documentation

## Related Work

Cowork Task:

Core Repo: http://34.143.229.138/gitea-admin/fsg-ai-core-assets

Core AI Issue:

Core Task:

Related PR:

## Scope

What is intentionally included?

What is intentionally NOT included?

## Validation

- [ ] Unit tests
- [ ] Integration tests
- [ ] Manual verification
- [ ] Regression check

Commands / evidence:

## Security Impact

Permission / credential / network / customer data impact:

## Compatibility

- [ ] No breaking change
- [ ] Breaking change documented

## Reviewer Notes

Anything Cowork reviewers should pay attention to.

---------

Co-authored-by: Anh Tran Nguyen Minh <anhtnm1@fpt.com>
Co-authored-by: Huong Le Thi Thien <huongltt35@fpt.com>
Co-authored-by: Nam Pham Dinh Thanh <nampdt@fpt.com>
Co-authored-by: Vu Dam Tuan <vudt15@fpt.com>
Co-authored-by: Hiep Ha Van <hiephv3@fpt.com>
Co-authored-by: Lam Hoang Van <lamhv7@fpt.com>
Reviewed-on: #7
Co-authored-by: Duy Le Huu <duylh19@fpt.com>
This commit was merged in pull request #7.
This commit is contained in:
2026-08-31 05:15:13 +00:00
committed by gitea-admin
co-authored by anhtnm1 huongltt35 Nam Pham Dinh Thanh vudt15 Hiep Ha Van lamhv7
parent 86c27e2e79
commit f9f6bc01fd
496 changed files with 68421 additions and 19688 deletions
+25
View File
@@ -21,6 +21,14 @@ AGENTS_DIR = CONFIG_DIR / "agents"
@dataclass
class CustomAgent:
"""Một agent do người dùng tự tạo: tên, mô tả, prompt mặc định và tuỳ chọn
provider/model riêng.
Bỏ trống ``provider``/``model`` nghĩa là dùng theo bước gọi nó hoặc theo cấu
hình chung — nhờ vậy một agent viết một lần chạy được với mọi provider.
Đã được ``core/co4e.py`` thay thế; giữ lại làm bản đối chiếu.
"""
name: str
description: str = ""
prompt: str = "" # default task; a Flow sub-agent can still override it
@@ -29,16 +37,25 @@ class CustomAgent:
@property
def slug(self) -> str:
"""Tên rút gọn an toàn để đặt tên file, ví dụ "Trợ lý Code" -> "tro-ly-code".
Tên không còn ký tự hợp lệ nào thì rơi về "agent".
"""
keep = "-_"
s = "".join(c if (c.isalnum() or c in keep) else "-" for c in self.name.strip().lower())
return "-".join(filter(None, s.split("-"))) or "agent"
def agents_dir() -> Path:
"""Thư mục chứa file agent tự tạo."""
return AGENTS_DIR
def list_agents(directory: Path = AGENTS_DIR) -> List[CustomAgent]:
"""Đọc mọi agent trong thư mục, sắp theo tên file.
File hỏng bị bỏ riêng lẻ chứ không làm hỏng cả danh sách — một file sai
không được phép làm mất hết agent còn lại.
"""
if not directory.exists():
return []
agents: List[CustomAgent] = []
@@ -58,6 +75,11 @@ def list_agents(directory: Path = AGENTS_DIR) -> List[CustomAgent]:
def save_agent(agent: CustomAgent, directory: Path = AGENTS_DIR, old_name: str = "") -> Path:
"""Ghi một agent xuống đĩa.
Truyền ``old_name`` khi đổi tên: file cũ bị xoá trước, nếu không sẽ có hai
file cùng nội dung với hai tên khác nhau.
"""
directory.mkdir(parents=True, exist_ok=True)
if old_name and old_name != agent.name:
delete_agent(old_name, directory)
@@ -67,6 +89,9 @@ def save_agent(agent: CustomAgent, directory: Path = AGENTS_DIR, old_name: str =
def delete_agent(name: str, directory: Path = AGENTS_DIR) -> None:
"""Xoá file của một agent theo tên. Không có file thì thôi; lỗi xoá bị nuốt,
không chặn giao diện.
"""
path = directory / f"{CustomAgent(name=name).slug}.json"
if path.exists():
try: