Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions agents/standard_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ def state(self) -> AgentState:

def solve(self, goal: str) -> ReasoningResult:
"""Solves a goal synchronously (library-style API)."""

if goal is None:
Copy link
Collaborator

@rishikesh-jentic rishikesh-jentic Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I appreciate you thinking about input validation—it's definitely something we should handle better.
I'd like to suggest a small refinement to make the UX even better. Instead of raising a ValueError, what do you think about returning a graceful result like this?
if not goal or not goal.strip(): return ReasoningResult(success=False, final_answer="Goal cannot be empty, please provide a goal")
My reasoning: In user-facing scenarios (chat interfaces, APIs, etc.), raising an exception forces the caller to handle it with try/except. Returning a failed ReasoningResult keeps the flow consistent—the caller always gets a result object, whether the input was valid or not.

Would like to hear your thoughts on this.

Thanks again for taking the time to improve the codebase! 🚀

raise ValueError("Goal cannot be None")
if not goal or not goal.strip():
raise ValueError("Goal cannot be empty or whitespace")

run_id = uuid4().hex
start_time = time.perf_counter()

Expand Down
38 changes: 38 additions & 0 deletions tests/agents/test_standard_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,42 @@ def test_agent_conversation_history_disabled_window():
agent.solve("g1")

assert memory.get("conversation_history") == []

def test_solve_raises_error_for_none_goal():
"""Test that solve raises ValueError when goal is None"""
agent = StandardAgent(
llm=DummyLLM(),
tools=DummyTools(),
memory=DictMemory(),
reasoner=DummyReasoner()
)

with pytest.raises(ValueError, match="Goal cannot be None"):
agent.solve(None)


def test_solve_raises_error_for_empty_goal():
"""Test that solve raises ValueError when goal is empty string"""
agent = StandardAgent(
llm=DummyLLM(),
tools=DummyTools(),
memory=DictMemory(),
reasoner=DummyReasoner()
)

with pytest.raises(ValueError, match="Goal cannot be empty or whitespace"):
agent.solve("")


def test_solve_raises_error_for_whitespace_goal():
"""Test that solve raises ValueError when goal is only whitespace"""
agent = StandardAgent(
llm=DummyLLM(),
tools=DummyTools(),
memory=DictMemory(),
reasoner=DummyReasoner()
)

with pytest.raises(ValueError, match="Goal cannot be empty or whitespace"):
agent.solve(" ")