diff options
author | Reinier van der Leer <pwuts@agpt.co> | 2024-02-16 18:17:51 +0100 |
---|---|---|
committer | Reinier van der Leer <pwuts@agpt.co> | 2024-02-16 18:19:04 +0100 |
commit | 666a5a8777779c591f56450255c5da974e9bbdba (patch) | |
tree | c24d654276e33d5e73213de6d9993c745934677c | |
parent | feat(benchmark): Get agent task cost from `Step.additional_output` (diff) | |
download | Auto-GPT-666a5a8777779c591f56450255c5da974e9bbdba.tar.gz Auto-GPT-666a5a8777779c591f56450255c5da974e9bbdba.tar.bz2 Auto-GPT-666a5a8777779c591f56450255c5da974e9bbdba.zip |
feat(agent/serve): Report task cost through `Step.additional_output`
- Added `task_cumulative_cost` and `task_total_cost` attributes to the `Step.additional_output` in the `AgentProtocolServer.execute_step` endpoint.
- Updated `agbenchmark` dependency in Agent and Forge
-rw-r--r-- | autogpts/autogpt/autogpt/app/agent_protocol_server.py | 27 | ||||
-rw-r--r-- | autogpts/autogpt/poetry.lock | 2 | ||||
-rw-r--r-- | autogpts/forge/poetry.lock | 2 |
3 files changed, 21 insertions, 10 deletions
diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.py index 131d2ad19..9c5965ba0 100644 --- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py +++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py @@ -233,14 +233,21 @@ class AgentProtocolServer: if step.is_last and execute_command == finish.__name__: assert execute_command_args + + additional_output = {} + task_total_cost = agent.llm_provider.get_incurred_cost() + if task_total_cost > 0: + additional_output["task_total_cost"] = task_total_cost + logger.info( + f"Total LLM cost for task {task_id}: " + f"${round(task_total_cost, 2)}" + ) + step = await self.db.update_step( task_id=task_id, step_id=step.step_id, output=execute_command_args["reason"], - ) - logger.info( - f"Total LLM cost for task {task_id}: " - f"${round(agent.llm_provider.get_incurred_cost(), 2)}" + additional_output=additional_output, ) return step @@ -320,6 +327,14 @@ class AgentProtocolServer: **raw_output, } + task_cumulative_cost = agent.llm_provider.get_incurred_cost() + if task_cumulative_cost > 0: + additional_output["task_cumulative_cost"] = task_cumulative_cost + logger.debug( + f"Running total LLM cost for task {task_id}: " + f"${round(task_cumulative_cost, 3)}" + ) + step = await self.db.update_step( task_id=task_id, step_id=step.step_id, @@ -328,10 +343,6 @@ class AgentProtocolServer: additional_output=additional_output, ) - logger.debug( - f"Running total LLM cost for task {task_id}: " - f"${round(agent.llm_provider.get_incurred_cost(), 3)}" - ) agent.state.save_to_json_file(agent.file_manager.state_file_path) return step diff --git a/autogpts/autogpt/poetry.lock b/autogpts/autogpt/poetry.lock index 5ae8a8adc..377aae109 100644 --- a/autogpts/autogpt/poetry.lock +++ b/autogpts/autogpt/poetry.lock @@ -51,7 +51,7 @@ uvicorn = "^0.23.2" type = "git" url = "https://github.com/Significant-Gravitas/AutoGPT.git" reference = "HEAD" -resolved_reference = "2a55efb3221600ec68496275022a94ade48ef79c" +resolved_reference = "21f1e64559ad3c292932ff1ea4d69abfe655280a" subdirectory = "benchmark" [[package]] diff --git a/autogpts/forge/poetry.lock b/autogpts/forge/poetry.lock index c2888ba55..a82c5e518 100644 --- a/autogpts/forge/poetry.lock +++ b/autogpts/forge/poetry.lock @@ -40,7 +40,7 @@ uvicorn = "^0.23.2" type = "git" url = "https://github.com/Significant-Gravitas/AutoGPT.git" reference = "HEAD" -resolved_reference = "2a55efb3221600ec68496275022a94ade48ef79c" +resolved_reference = "21f1e64559ad3c292932ff1ea4d69abfe655280a" subdirectory = "benchmark" [[package]] |