Skip to content

Conversation

@RonaldJEN
Copy link

Description

This PR introduces the StreamRolePlaying class in owl/utils/enhanced_role_playing.py. This class extends the base RolePlaying society to support step-by-step agent interactions while generating an event stream for single interaction steps.

Key Features:

  • Single Interaction Event Stream: Emits events for key phases (e.g., START_OF_WORKFLOW, END_OF_WORKFLOW, START_OF_AGENT, END_OF_AGENT, MESSAGE, TOOL_CALL, START_OF_LLM, END_OF_LLM, ERROR), reflecting the status of a single interaction step.
  • Synchronous & Asynchronous: Provides both step_stream and astep_stream methods for processing a single step and generating events.
  • Custom System Messages: Includes logic to generate specific system prompts for assistant and user agents based on the task.
  • Workflow Tracking: Uses unique IDs (workflow_id, agent ID, message ID, tool call ID) for better tracking within the event stream.

Important Limitations & Future Outlook:

  • Not Fully Streaming: Please note that due to the underlying ChatAgent not yet fully supporting streaming Tool Calling and streaming message content output, StreamRolePlaying currently implements event streaming for single agent interaction steps, not a complete end-to-end streaming experience. The entire agent response (including thought process and final message) is generated at once after the step completes.
  • Providing an Idea for the Future: Despite current limitations, this implementation explores a method for deconstructing and observing the agent interaction process via an event stream. We hope this event stream pattern can offer a valuable reference point for implementing true end-to-end streaming (including streaming tool calls and message output) in ChatAgent in the future.
  • Anticipating Official Support: We strongly anticipate and hope that Camel AI official will soon provide native support for full streaming capabilities at the ChatAgent level. This would significantly enhance user experience and interaction real-time responsiveness.

Adds the StreamRolePlaying class, inheriting from RolePlaying.
This class supports step-by-step execution of agent interactions and generates an event stream for single interaction steps, used to track workflow state (e.g., Agent Start/End, LLM Start/End, Message, Tool Call).

Key Features:
- Synchronous (`step_stream`) and asynchronous (`astep_stream`) event stream generation, currently limited to single agent interactions.
- Generates customized system messages for assistant and user agents..

Note: Due to limitations in the underlying ChatAgent (lack of full support for streaming tool calls and message output), this implementation provides event streaming for individual interaction steps, not end-to-end true streaming.
Copy link
Collaborator

@fengju0213 fengju0213 left a comment

Choose a reason for hiding this comment

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

thanks @RonaldJEN Sorry for the delayed review. left some comments,additionally, the current implementation uses the chatagent.step() method, which is typically non-streaming. If you're interested, we'd welcome your contribution to address this in CAMEL by working on issue #2069:
camel-ai/camel#2069

Please don't hesitate to reach out if you need any support from our team.

self.user_sys_msg = self.user_agent.system_message

def create_custom_system_messages(self,task_prompt: str):
"""创建自定义系统消息
Copy link
Collaborator

Choose a reason for hiding this comment

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

We prefer to use English comments.

)
self.user_sys_msg = self.user_agent.system_message

def create_custom_system_messages(self,task_prompt: str):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we can change this to a private method (using _prefix)

Unless told the task is complete, always structure your responses as:
Solution:
[Your detailed solution here in Chinese, including code, explanations, and step-by-step instructions]
Copy link
Collaborator

Choose a reason for hiding this comment

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

The language here should be defined by {output_language}

Always end with "Next request."
"""

CUSTOM_USER_SYSTEM_PROMPT = """===== USER GUIDELINES =====
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe we can define the output_language in system prompt

END_OF_AGENT = "end_of_agent"
MESSAGE = "message"
TOOL_CALL = "tool_call"
ERROR = "error" # New event for handling issues
Copy link
Collaborator

Choose a reason for hiding this comment

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

This event doesn't seem to be used later - could we potentially utilize it during error handling? We could yield an ERROR event within a try...except block.

"data": {"agent_id": assistant_agent_id}
}

def get_last_step_result(self) -> Tuple[ChatAgentResponse, ChatAgentResponse]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

The current implementation might confuse users since they may not know how to use this function. Perhaps we could add an example for the new streaming output?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants