Adds context information to the agent's output.
Parameters:
| Name | Type | Description | Default |
output | `str` | output generated by the agent. | required |
tools_executed | `list[str]` | name of executed tools in execution order. | required |
Returns:
| Type | Description |
str | str: output provided with the context information as a quote markdown section. |
Source code in projects/gptstonks_api/gptstonks/api/explicability/explicability.py
| def add_context_to_output(output: str, tools_executed: list[str]) -> str:
"""Adds context information to the agent's output.
Args:
output (`str`): output generated by the agent.
tools_executed (`list[str]`): name of executed tools in execution order.
Returns:
`str`: output provided with the context information as a quote markdown section.
"""
openbb_context = "> Context retrieved using OpenBB."
complete_context = (
f"> Context retrieved using {','.join(list(set(tools_executed)))}."
if len(tools_executed) > 0
else "> Answer generated with the AI's own knowledge."
)
return (
output.replace(openbb_context, complete_context)
if openbb_context in output
else f"{complete_context}\n\n{output}"
)
|