Add teaching Python agent CLI with Poetry and CI

This commit is contained in:
Shawn Bot
2026-04-02 10:09:34 +00:00
parent 0b4e0c0ae9
commit 3e979daa61
27 changed files with 2181 additions and 0 deletions

23
tests/test_agent.py Normal file
View File

@@ -0,0 +1,23 @@
from agt.agent import Agent, Tool, echo_tool
def test_agent_returns_default_message() -> None:
agent = Agent()
agent.register_tool(Tool("echo", "Echo input text", echo_tool))
result = agent.run("hello")
assert "教学用 Agent 骨架" in result
assert agent.messages[0].role == "user"
assert agent.messages[-1].role == "assistant"
def test_load_skills_finds_skill_md(tmp_path) -> None:
skill_dir = tmp_path / "skills" / "writing"
skill_dir.mkdir(parents=True)
(skill_dir / "SKILL.md").write_text("# writing", encoding="utf-8")
agent = Agent()
skills = agent.load_skills(tmp_path / "skills")
assert skills == ["writing"]

30
tests/test_cli.py Normal file
View File

@@ -0,0 +1,30 @@
from pathlib import Path
from subprocess import run
import sys
ROOT = Path(__file__).resolve().parents[1]
def test_cli_lists_skills(tmp_path) -> None:
skill_dir = tmp_path / "skills" / "analysis"
skill_dir.mkdir(parents=True)
(skill_dir / "SKILL.md").write_text("# analysis", encoding="utf-8")
result = run(
[
sys.executable,
"-m",
"agt.cli",
"--skills-dir",
str(tmp_path / "skills"),
"--list-skills",
],
cwd=ROOT,
capture_output=True,
text=True,
check=False,
)
assert result.returncode == 0
assert "analysis" in result.stdout