agentscope
agentscope copied to clipboard
Add notebook executor as service function and add codeact agent.
Description
- Example for the codeact agent use the notebook executor interactively. Reference https://github.com/xingyaoww/code-act for more information.
- Service function can be use with states inside a class. e.g.
from agentscope.service.service_toolkit import *
from agentscope.service.service_status import ServiceExecStatus
from agentscope.service.service_response import ServiceResponse
class Counter:
def __init__(self, c=0):
self.c = c
def add_counter(self, a: int):
"""
The counter for agent to use. Add `a` to the count value.
Args:
a (`int`):
The number to add to count value.
Returns:
count_value += a
"""
self.c += a
return ServiceResponse(ServiceExecStatus.SUCCESS, self.c)
counter = Counter(0)
service_toolkit = ServiceToolkit()
service_toolkit.add(counter.add_counter)
print(service_toolkit.tools_instruction)
input_obs = [{"name": "add_counter", "arguments":{"a": 1}}]
res_of_string_input = service_toolkit.parse_and_call_func(input_obs)
print(res_of_string_input)
Checklist
Please check the following items before code is ready to be reviewed.
- [x] Code has passed all tests
- [x] Docstrings have been added/updated in Google Style
- [x] Documentation has been updated
- [x] Code is ready for review