mirror of
https://github.com/tvytlx/ai-agent-deep-dive.git
synced 2026-04-03 07:34:50 +08:00
Fix tests for fake LLM response
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
from agt.agent import Agent, Tool, echo_tool
|
||||
from agt.agent import Agent, FakeLLMClient, Tool, echo_tool
|
||||
|
||||
|
||||
def test_agent_returns_default_message() -> None:
|
||||
agent = Agent()
|
||||
def test_agent_returns_fake_llm_message() -> None:
|
||||
agent = Agent(llm=FakeLLMClient())
|
||||
agent.register_tool(Tool("echo", "Echo input text", echo_tool))
|
||||
|
||||
result = agent.run("hello")
|
||||
|
||||
assert "教学用 Agent 骨架" in result
|
||||
assert "[fake-llm]" in result
|
||||
assert "hello" in result
|
||||
assert agent.messages[0].role == "user"
|
||||
assert agent.messages[-1].role == "assistant"
|
||||
|
||||
@@ -21,3 +22,13 @@ def test_load_skills_finds_skill_md(tmp_path) -> None:
|
||||
skills = agent.load_skills(tmp_path / "skills")
|
||||
|
||||
assert skills == ["writing"]
|
||||
|
||||
|
||||
def test_fake_llm_streams_multiple_chunks() -> None:
|
||||
llm = FakeLLMClient()
|
||||
from agt.agent import Message
|
||||
|
||||
chunks = list(llm.stream_text([Message(role="user", content="x")]))
|
||||
|
||||
assert len(chunks) >= 2
|
||||
assert "".join(chunks).startswith("[fake-llm]")
|
||||
|
||||
Reference in New Issue
Block a user