AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
feat(agent/serve): Report task cost through `Step.additional_output`
Reinier van der Leer666a5a877777
diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.pyindex 131d2ad198..9c5965ba04 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 stepdiff --git a/autogpts/autogpt/poetry.lock b/autogpts/autogpt/poetry.lockindex 5ae8a8adc6..377aae109f 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.lockindex c2888ba553..a82c5e5181 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]]