Skip to content

Conversation

@yanxi0830
Copy link
Contributor

@yanxi0830 yanxi0830 commented Feb 4, 2025

What does this PR do?

Feature/Issue validation/testing/test plan

python -m examples.agents.react_agent
image image

Sources

Please link relevant resources if necessary.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Thanks for contributing 🎉!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Feb 4, 2025
@yanxi0830 yanxi0830 marked this pull request as draft February 4, 2025 19:59
@yanxi0830 yanxi0830 changed the title [WIP] ReACT agent example [RFC] ReACT agent example Feb 4, 2025
@yanxi0830 yanxi0830 marked this pull request as ready for review February 4, 2025 20:03
from llama_stack_client.types.tool_def_param import Parameter


class TorchtuneTool(ClientTool):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will remove ClientTool into decorator in following PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yanxi0830 added a commit to llamastack/llama-stack-client-python that referenced this pull request Feb 5, 2025
# What does this PR do?

- See llamastack/llama-stack#975

**Changes**
✅  Bugfix ToolResponseMessage role
✅  Add ReACT default prompt + default output parser
✅  Add ReACTAgent wrapper
🚧 Remove ClientTool and simplify it as a decorator (separate PR,
including llama-stack-apps)
✅  Make agent able to return structured outputs
- Note that some remote provider do not support response_format
structured outputs, add it as an optional flag when calling `ReActAgent`
wrapper.

## Test Plan

see test in llamastack/llama-stack-apps#166

## Sources

Please link relevant resources if necessary.


## Before submitting

- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Ran pre-commit to handle lint / formatting issues.
- [ ] Read the [contributor
guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md),
      Pull Request section?
- [ ] Updated relevant documentation.
- [ ] Wrote necessary unit or integration tests.
@yanxi0830
Copy link
Contributor Author

Merge until llamastack/llama-stack-client-python#121 is released into pypi package.


model = "meta-llama/Llama-3.1-8B-Instruct"

agent = ReActAgent(
Copy link
Contributor

Choose a reason for hiding this comment

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

What's your thinking behind having ReActAgent vs ReActAgentConfig + Agent? I seems that the former hides some configurations that were available, e.g. max_infer_iters? And the latter is consistent with how Agent is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ReActAgent is a simple wrapper and helper class that hides the configuration needed to create a ReActAgentConfig + Agent, otherwise they are the same. We can override configurations with custom_agent_config, and that brings it the same as using Agent.

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't it just as simple with ReActAgentConfig + Agent? Just one extra line to instantiate the Agent? Then we don't need custom_agent_config.

Copy link
Contributor Author

@yanxi0830 yanxi0830 Feb 6, 2025

Choose a reason for hiding this comment

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

Yeah, I guess its the difference b/w:

agent = ReActAgent(client, model, builtin_toolgroups, client_tools)

v.s.

agent_config = get_react_agent_config(builtin_toolgroups, client_tools, json_response_format)
agent = Agent(client, agent_config, client_tools, output_parser=ReActOutputParser())

former hides agent_config & output_parser, while latter needs users to know about output_parser, I guess its a matter of how much we want to hide from users

yanxi0830 added a commit to llamastack/llama-stack-client-python that referenced this pull request Feb 5, 2025
# What does this PR do?

- address comments in
#121


## Test Plan

- see llamastack/llama-stack-apps#166

## Sources

Please link relevant resources if necessary.


## Before submitting

- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Ran pre-commit to handle lint / formatting issues.
- [ ] Read the [contributor
guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md),
      Pull Request section?
- [ ] Updated relevant documentation.
- [ ] Wrote necessary unit or integration tests.
yanxi0830 added a commit to llamastack/llama-stack-client-python that referenced this pull request Feb 6, 2025
# What does this PR do?

- Add decorator for on callables for defining client side custom tools
- Addresses: llamastack/llama-stack#948

## Test Plan

Usage:
```python
@client_tool
def add(x: int, y: int) -> int:
    '''Add 2 integer numbers
    
            :param x: integer 1
            :param y: integer 2
            :returns: sum of x + y
    '''
    return x + y
```

`add` will be a ClientTool that can be passed

- Working example in:
llamastack/llama-stack-apps#166


## Sources

Please link relevant resources if necessary.


## Before submitting

- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Ran pre-commit to handle lint / formatting issues.
- [ ] Read the [contributor
guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md),
      Pull Request section?
- [ ] Updated relevant documentation.
- [ ] Wrote necessary unit or integration tests.
yanxi0830 added a commit to llamastack/llama-stack-client-python that referenced this pull request Feb 7, 2025
# What does this PR do?

- See discussion in
#121 (comment)

## Test Plan

test with llamastack/llama-stack-apps#166

```
LLAMA_STACK_BASE_URL=http://localhost:8321 pytest -v tests/client-sdk/agents/test_agents.py::test_override_system_message_behavior --inference-model "meta-llama/Llama-3.3-70B-Instruct"
```
<img width="1697" alt="image"
src="https://github.com/user-attachments/assets/c036cbf6-9fc1-4064-82af-fa1984300653"
/>


## Sources

Please link relevant resources if necessary.


## Before submitting

- [ ] This PR fixes a typo or improves the docs (you can dismiss the
other checks if that's the case).
- [ ] Ran pre-commit to handle lint / formatting issues.
- [ ] Read the [contributor
guideline](https://github.com/meta-llama/llama-stack/blob/main/CONTRIBUTING.md),
      Pull Request section?
- [ ] Updated relevant documentation.
- [ ] Wrote necessary unit or integration tests.
@ashwinb ashwinb changed the title [RFC] ReACT agent example feat: ReACT agent example Feb 7, 2025
@ashwinb ashwinb merged commit 37c4100 into main Feb 7, 2025
1 check passed
@ashwinb ashwinb deleted the react_agent branch February 7, 2025 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants