-
Notifications
You must be signed in to change notification settings - Fork 2k
Refactor code agent system prompt #1153
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
Conversation
2f30c4e
to
3113c0f
Compare
@@ -210,6 +201,16 @@ def __init__( | |||
self.agent_name = self.__class__.__name__ | |||
self.model = model | |||
self.prompt_templates = prompt_templates or EMPTY_PROMPT_TEMPLATES | |||
if prompt_templates is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These asserts should guide users trying to customize their agent's prompts.
@@ -113,18 +113,15 @@ system_prompt: |- | |||
If no tool call is needed, use final_answer tool to return your answer. | |||
4. Never re-do a tool call that you previously did with the exact same parameters. | |||
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the monetary reward because putting an objective like this can help exploits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny hack 👍
@@ -158,7 +158,7 @@ def parse_json_blob(json_blob: str) -> Tuple[Dict[str, str], str]: | |||
json_data = json.loads(json_data, strict=False) | |||
return json_data, json_blob[:first_accolade_index] | |||
except IndexError: | |||
raise ValueError("The JSON blob you used is invalid") | |||
raise ValueError("The model output does not contain any JSON blob.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarify the error.
Takes inputs: {{tool.inputs}} | ||
Returns an output of type: {{tool.output_type}} | ||
{%- endfor %} | ||
def {{ tool.name }}({% for arg_name, arg_info in tool.inputs.items() %}{{ arg_name }}: {{ arg_info.type }}{% if not loop.last %}, {% endif %}{% endfor %}) -> {{tool.output_type}}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make tool definitions look like python functions: should be easier to read for the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aymeric-roucher. Just leaving a few comments.
initial_plan="", | ||
update_facts_pre_messages="", | ||
update_facts_post_messages="", | ||
update_plan_pre_messages="", | ||
update_plan_post_messages="", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: In a future PR, it would be great to migrate PlanningPromptTemplate
, ManagedAgentPromptTemplate
, FinalAnswerPromptTemplate
, and PromptTemplates
to pydantic.BaseModel
to enable default initialization. Ultimately, this will allow for a simpler declaration:
EMPTY_PROMPT_TEMPLATES = PromptTemplates()
missing_keys = set(EMPTY_PROMPT_TEMPLATES.keys()) - set(prompt_templates.keys()) | ||
assert not missing_keys, ( | ||
f"Some prompt templates are missing from your custom `prompt_templates`: {missing_keys}" | ||
) | ||
for key in EMPTY_PROMPT_TEMPLATES.keys(): | ||
for subkey in EMPTY_PROMPT_TEMPLATES[key]: | ||
assert subkey in prompt_templates[key], ( | ||
f"Some prompt templates are missing from your custom `prompt_templates`: {subkey} under {key}" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi: A Pydantic PromptTemplates
model enables automatic validation. The code could simply be:
PromptTemplates(**prompt_templates) # It raises an error if any field or type doesn't match `PromptTemplates`
Alternatively, the function could accept only a PromptTemplates
BaseModel instance as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will also make the EMPTY_PROMPT_TEMPLATES
variable unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@albertvillanova pointer for discussion when you come back.
@@ -113,18 +113,15 @@ system_prompt: |- | |||
If no tool call is needed, use final_answer tool to return your answer. | |||
4. Never re-do a tool call that you previously did with the exact same parameters. | |||
Now Begin! If you solve the task correctly, you will receive a reward of $1,000,000. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny hack 👍
Co-authored-by: A-Mahla <89754740+A-Mahla@users.noreply.github.com>
No description provided.