valuecell
valuecell copied to clipboard
NewsAgent.stream yields raw dict on error instead of StreamResponse, causing GenericAgentExecutor to raise ValueError`
Affected File & Lines
python/valuecell/agents/news_agent/core.py:75-78python/valuecell/core/agent/decorator.py:185-188
Severity & Impact
- Severity: High
- Impact: System reliability and error handling crash. When
NewsAgentencounters an upstream failure (e.g. news provider timeout, bad payload, API rate limit), it attempts to return an error by yielding{"type": "error", "content": ...}. The A2A decorator (GenericAgentExecutor) expects onlyStreamResponseorNotifyResponseobjects. Yielding a dictionary causesdecorator.pyto raise an uncaughtValueError: Agent NewsAgent yielded invalid response type: <class 'dict'>. This masks the underlying error from both server logs and the frontend client, leaving tasks in a failed state with cryptic messages.
Root Cause Analysis
In python/valuecell/agents/news_agent/core.py:75-78:
except Exception as e:
logger.error(f"Error processing news query: {str(e)}")
logger.exception("Full error details:")
yield {"type": "error", "content": f"Error processing news query: {str(e)}"}
In python/valuecell/core/agent/decorator.py:185-188:
async for response in query_handler(query, context_id, task_id, dependencies):
if not isinstance(response, (StreamResponse, NotifyResponse)):
raise ValueError(
f"Agent {agent_name} yielded invalid response type: {type(response)}"
)
Every streaming agent in ValueCell must yield StreamResponse instances. The core response factory (valuecell/core/agent/responses.py) provides streaming.failed(content) for this exact purpose:
def failed(self, content: Optional[str] = None) -> StreamResponse:
return StreamResponse(content=content, event=TaskStatusEvent.TASK_FAILED)
Steps to Reproduce
Run the following script:
import sys
sys.path.insert(0, r"python")
from valuecell.core.types import StreamResponse, NotifyResponse
class MockNewsAgent:
def stream_with_error(self):
try:
raise ConnectionError("Upstream news API timeout / rate limit")
except Exception as e:
# Matches line 78 in python/valuecell/agents/news_agent/core.py
yield {"type": "error", "content": f"Error processing news query: {str(e)}"}
agent = MockNewsAgent()
for response in agent.stream_with_error():
if not isinstance(response, (StreamResponse, NotifyResponse)):
raise ValueError(f"Agent NewsAgent yielded invalid response type: {type(response)}")
Observed Behavior (Evidence)
Traceback (most recent call last):
File "test_bug3_newsagent.py", line 18, in <module>
raise ValueError(f"Agent NewsAgent yielded invalid response type: {type(response)}")
ValueError: Agent NewsAgent yielded invalid response type: <class 'dict'>
Expected Behavior
NewsAgent.stream() should yield a valid StreamResponse utilizing streaming.failed(...), allowing GenericAgentExecutor to handle task status transitions cleanly without throwing a type validation exception.
Proposed Fix
--- a/python/valuecell/agents/news_agent/core.py
+++ b/python/valuecell/agents/news_agent/core.py
@@ -75,4 +75,4 @@ class NewsAgent:
except Exception as e:
logger.error(f"Error processing news query: {str(e)}")
logger.exception("Full error details:")
- yield {"type": "error", "content": f"Error processing news query: {str(e)}"}
+ yield streaming.failed(f"Error processing news query: {str(e)}")