Skip to content

Commit

Permalink
Change return to yield
Browse files Browse the repository at this point in the history
  • Loading branch information
aymeric-roucher committed May 27, 2024
1 parent ca0e85b commit 59bb0b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/transformers/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def stream_run(self, task: str, **kwargs):
final_step_log["final_answer"] = final_answer
yield final_step_log

return final_answer
yield final_answer


def direct_run(self, task: str, **kwargs):
Expand Down
17 changes: 6 additions & 11 deletions src/transformers/agents/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ def download_prompt(prompt_or_repo_id, agent_name, mode="run"):
Make sure to have the $INPUT as a dictionnary in the right format for the tool you are using, and do not put variable names as input if you can find the right values.
You will be given:
Task: the task you are given.
You should ALWAYS use the following format:
Thought: you should always think about one action to take. Then use the action as follows:
Expand Down Expand Up @@ -266,10 +262,10 @@ def download_prompt(prompt_or_repo_id, agent_name, mode="run"):


DEFAULT_REACT_CODE_SYSTEM_PROMPT = """You will be given a task to solve as best you can.
To do so, you have been given access to tools that are basically Python functions which you can call with code.
To do so, you have been given access to *tools*: these tools are basically Python functions which you can call with code.
To solve the task, you must plan forward to proceed in a series of steps, in a cycle of 'Thought:', 'Code:', and 'Observation:' sequences.
At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task, then the tools that you want to use.
At each step, in the 'Thought:' sequence, you should first explain your reasoning towards solving the task and the tools that you want to use.
Then in the 'Code:' sequence, you should write the code in simple Python. The code sequence must end with '<end_action>' sequence.
During each intermediate step, you can use 'print()' to save whatever important information you will then need.
These print outputs will then appear in the 'Observation:' field, which will be available as input for the next step.
Expand Down Expand Up @@ -307,7 +303,7 @@ def download_prompt(prompt_or_repo_id, agent_name, mode="run"):
```<end_action>
---
Task: "Which city has the highest population , Guangzhou or Shanghai?"
Task: "Which city has the highest population: Guangzhou or Shanghai?"
Thought: I need to get the populations for both cities and compare them: I will use the tool `search` to get the population of both cities.
Code:
Expand Down Expand Up @@ -350,14 +346,13 @@ def download_prompt(prompt_or_repo_id, agent_name, mode="run"):
<<tool_descriptions>>
You also can perform computations in the python code that you generate.
You also can perform computations in the Python code that you generate.
Here are the rules you should always follow to solve your task:
1. Always provide a 'Thought:' sequence, and a 'Code:\n```py' sequence ending with '```<end_action>' sequence, else you will fail.
2. Use only variables that you defined!
2. Use only variables that you have defined!
3. Always use the right arguments for the tools. DO NOT pass the arguments as a dict as in 'answer = ask_search_agent({'query': "What is the place where James Bond lives?"})', but use the arguments directly as in 'answer = ask_search_agent(query="What is the place where James Bond lives?")'.
4. In the code you generate, you can do several tool calls in parallel, but do not perform too many tool calls sequentially in a single block, especialy when the output of one tool call is in an unpredictable format: in that case rather split the task into intermediate code blocks, then use print() to save the intermediate result. Finally, use final_answer() to return the final result.
For instance if you need to call search for three independant topics, you can do three calls in the same code block. But if you're waiting for the ouput of one search call to generate an image, rather print the search output, then generate the image in the next step.
4. Take care to not chain too many sequential tool calls in the same code block, especially when the output format is unpredictable. For instance, a call to search has an unpredictable return format, so do not have another tool call that depends on its output in the same block: rather output results with print() to use them in the next block.
5. Call a tool only when needed, and never re-do a tool call that you previously did with the exact same parameters.
6. Don't name any new variable with the same name as a tool: for instance don't name a variable 'final_answer'.
Expand Down

0 comments on commit 59bb0b1

Please sign in to comment.