Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stream output for Agent #834

Closed
wants to merge 1 commit into from
Closed

Add stream output for Agent #834

wants to merge 1 commit into from

Conversation

Undertone0809
Copy link
Owner

@Undertone0809 Undertone0809 commented Aug 3, 2024

Related to #833

Add stream mode output to ToolAgent.

  • Modify promptulate/agents/tool_agent/agent.py to add a stream parameter to the run method and implement logic to handle streaming output.
  • Update example/agent/tool_agent_usage.py to demonstrate the usage of agent.run(..., stream=True).
  • Add tests in tests/agents/test_tool_agent.py to verify the stream mode output functionality.

For more details, open the Copilot Workspace session.

Summary by CodeRabbit

  • New Features

    • Introduced real-time streaming responses for the tool agent, enhancing interactivity and responsiveness when executing commands.
  • Bug Fixes

    • Improved the _run method to allow optional streaming output, ensuring better responsiveness during LLM interactions.
  • Tests

    • Added a new test to evaluate the tool agent's functionality in stream mode, increasing test coverage for new streaming capabilities.

Related to #833

Add stream mode output to ToolAgent.

* Modify `promptulate/agents/tool_agent/agent.py` to add a `stream` parameter to the `run` method and implement logic to handle streaming output.
* Update `example/agent/tool_agent_usage.py` to demonstrate the usage of `agent.run(..., stream=True)`.
* Add tests in `tests/agents/test_tool_agent.py` to verify the stream mode output functionality.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/Undertone0809/promptulate/issues/833?shareId=XXXX-XXXX-XXXX-XXXX).
Copy link

coderabbitai bot commented Aug 3, 2024

Walkthrough

The changes enhance the ToolAgent's capabilities by introducing streaming responses in its execution flow. By modifying the agent.run method and the underlying _run method, the agent can now deliver real-time feedback, improving interactivity. Additionally, new tests ensure that this functionality works as intended, providing better coverage for streaming scenarios. Overall, these updates significantly boost the responsiveness and usability of the tool agent.

Changes

Files Change Summary
example/agent/tool_agent_usage.py Modified agent.run to handle streaming responses, iterating over outputs in real-time to enhance interactivity.
promptulate/agents/tool_agent/agent.py Added a stream parameter to _run method for controlling output streaming, improving responsiveness during interactions.
tests/agents/test_tool_agent.py Introduced test_stream_mode to verify the ToolAgent's operation in stream mode, ensuring it handles streaming responses correctly.

Poem

🐰 In the meadow, tools now dance,
Streaming responses, what a chance!
Feedback flows like a gentle stream,
Enhancing the agent’s wondrous dream.
With every word, a leap we take,
A joyful hop for innovation's sake! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 11b21d8 and 7262b06.

Files selected for processing (3)
  • example/agent/tool_agent_usage.py (1 hunks)
  • promptulate/agents/tool_agent/agent.py (2 hunks)
  • tests/agents/test_tool_agent.py (1 hunks)
Additional context used
Ruff
promptulate/agents/tool_agent/agent.py

122-122: Line too long (93 > 88)

(E501)

Additional comments not posted (3)
example/agent/tool_agent_usage.py (1)

13-14: LGTM! Ensure proper usage of the new streaming functionality.

The code changes are approved. The for-loop correctly handles streaming responses from agent.run.

However, ensure that all function calls to agent.run with stream=True are correctly handled in the codebase.

tests/agents/test_tool_agent.py (1)

58-64: LGTM! Ensure comprehensive test coverage.

The code changes are approved. The test function correctly tests the streaming functionality of ToolAgent.

However, ensure that the test coverage is comprehensive and includes edge cases.

promptulate/agents/tool_agent/agent.py (1)

178-180: LGTM! Ensure proper usage of the new streaming functionality.

The code changes are approved. The changes correctly handle streaming responses by yielding results if stream is True.

However, ensure that all method calls to _run with stream=True are correctly handled in the codebase.

@@ -119,13 +119,14 @@ def current_date(self) -> str:
return f"Current date: {time.strftime('%Y-%m-%d %H:%M:%S')}"

def _run(
self, instruction: str, return_raw_data: bool = False, **kwargs
self, instruction: str, return_raw_data: bool = False, stream: bool = False, **kwargs
Copy link

Choose a reason for hiding this comment

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

Refactor for line length.

The line exceeds the maximum line length of 88 characters.

-        self, instruction: str, return_raw_data: bool = False, stream: bool = False, **kwargs
+        self, instruction: str, return_raw_data: bool = False, 
+        stream: bool = False, **kwargs
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
self, instruction: str, return_raw_data: bool = False, stream: bool = False, **kwargs
self, instruction: str, return_raw_data: bool = False,
stream: bool = False, **kwargs
Tools
Ruff

122-122: Line too long (93 > 88)

(E501)

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.

1 participant