Skip to content

Commit 3bb882f

Browse files
Add cache_complete_prompt option for caching complete prompts in LLM response for claude.
1 parent 3fd1e59 commit 3bb882f

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/agentlab/agents/tool_use_agent/multi_tool_agent.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,10 @@ def get_action(self, obs: Any) -> float:
392392
self.config.summarizer.apply(self.llm, self.messages)
393393
logging.info("Main tool calling")
394394
response: LLMOutput = self.llm(
395-
messages=self.messages, tool_choice="any", cache_tool_definition=True
395+
messages=self.messages,
396+
tool_choice="any",
397+
cache_tool_definition=True,
398+
cache_complete_prompt=True,
396399
)
397400
logging.info(f"Obtained response {response}")
398401

src/agentlab/llm/response_api.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ def _call_api(
537537
if kwargs.pop("cache_tool_definition", False):
538538
# Indicating cache control for the last tool enables caching of all previous tool definitions.
539539
api_params["tools"][-1]["cache_control"] = {"type": "ephemeral"}
540+
if kwargs.pop("cache_complete_prompt", False):
541+
# Indicating cache control for the last message enables caching of the complete prompt.
542+
api_params["messages"][-1]["content"][-1]["cache_control"] = {"type": "ephemeral"}
540543
if self.extra_kwargs.get("reasoning", None) is not None:
541544
api_params["reasoning"] = self.extra_kwargs["reasoning"]
542545

0 commit comments

Comments
 (0)