Open fahdmirza opened 1 month ago
@fahdmirza Thanks for your attention.
The text box is used to give the user input in jupyter. In this example, the user (you) is talking to an agent equipped with some tools.
The following code snippet in your code describes the order of speech, which requires the user to speak first. So just input something in the text box (like hello or sth), and then the agent will give a feedback. When user input "exit", the conversation loop will end.
# ...
x = None
while True:
x = user(x)
if x.content == "exit":
break
x = agent(x)
If you want to adjust the order (agent speaks first), just modify the above code as follows:
# ...
x = None
while True:
x = agent(x)
x = user(x)
if x.content == "exit":
break
Sorry @DavdGao , my question and issue is different. How do I call the function from the main python code? Please check my original post again. Thanks.
Sorry, but I'm a little confused about "call the function from the main python code".
However, in ReAct Agent example, the tool function execute_python_code
is given to the agent as a candidated tool, and it's the react agent will decide whether to use this tool function rather than user, and the choiced tool function will be executed within the agent automatically. Refer to the source code of react agent for more details.
The following is the combined system prompt of this react agent (print(agent.sys_prompt)
), which provides the tool function for the agent to use.
You're a helpful assistant. Your name is assistant.
## Tool Functions:
The following tool functions are available in the format of
{index}. {function name}: {function description} {argument1 name} ({argument type}): {argument description} {argument2 name} ({argument type}): {argument description} ...
1. bing_search: Search question in Bing Search API and return the searching results
question (string): The search query string.
2. execute_python_code: Execute Python code and capture the output. Note you must `print` the output to get the result.
code (string): The Python code to be executed.
3. read_text_file: Read the content of the text file.
file_path (string): The path to the text file to be read.
4. write_text_file: Write content to a text file.
file_path (string): The path to the file where content will be written.
overwrite (boolean): Whether to overwrite the file if it already exists.
content (string): Content to write into the file.
## What You Should Do:
1. First, analyze the current situation, and determine your goal.
2. Then, check if your goal is already achieved. If so, try to generate a response. Otherwise, think about how to achieve it with the help of provided tool functions.
3. Respond in the required format.
## Note:
1. Fully understand the tool functions and their arguments before using them.
2. You should decide if you need to use the tool functions, if not then return an empty list in "function" field.
3. Make sure the types and values of the arguments you provided to the tool functions are correct.
4. Don't take things for granted. For example, where you are, what's the time now, etc. You can try to use the tool functions to get information.
5. If the function execution fails, you should analyze the error and try to solve it.
If you want the agent to call the function, just ask it to finish some tasks that may require this tool function. For example, I ask the react agent to solve a complex calculation problem, and it will call the execute_python_code
function.
Hope this could answer your question.
@DavdGao Thanks for your response. I tried but its not doing anything. Is it possible to get an end-to-end example please? I am trying to review agentscope for my channel https://www.youtube.com/@fahdmirza . Thanks.
Please provide more information, for example, the running log.
I have tried your code in the issue description, and asked the agent to calculate a number as shown in the following video.
In the beginning, the llama3.1 model responds in the correct format and the function executes successfully. However, llama3.1 fails to generate a final respond with the tag <response>xxx</response>
and keeps on calculating the number. So a more powerful llm is suggested in this case.
https://github.com/user-attachments/assets/d661e968-b99d-4d32-8047-4784973b3004
Hi, I am sorry, I am not sure what you are doing there as the code simply doesn't work with Ollama. There is no end-to-end example in your documentation and I am not sure what you are saying above. The link to source code which you posted doesnt help at all. I have again wasted 3 hours today trying to get this work. With all due respect, I would suggest improving your documentation and putting in some better end-to-end examples.
Hello, I am just trying to create a simple end to end example to call a python function from agentscope. When I run it in jupyter notebook, it runs fine and gives me text box. I am confused as how to call that function now, or in other words how to use this? I have tried documentation (which can be greatly improved) but couldn't find any help there. Following is my code:
Please advise.