Skip to content

Commit 0e8516a

Browse files
committed
Add prompt caching
1 parent 1338b49 commit 0e8516a

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

requirements-constraints.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ chromadb==0.4.14
9999
google-cloud-storage==2.*
100100
google-cloud-aiplatform==1.*
101101
google-cloud-secret-manager==2.*
102-
anthropic[vertex]==0.34.2
102+
anthropic[vertex]==0.41.0
103103
langfuse @ git+https://github.com/jennmueng/langfuse-python.git@9d9350de1e4e84fa548fe84f82c1b826be17956e
104104
watchdog
105105
stumpy==1.13.0

requirements.txt

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ amqp==5.3.1
2121
# via kombu
2222
annotated-types==0.7.0
2323
# via pydantic
24-
anthropic==0.34.2
24+
anthropic==0.41.0
2525
# via -r requirements-constraints.txt
2626
anyio==4.7.0
2727
# via
@@ -268,7 +268,7 @@ httpcore==1.0.7
268268
# via httpx
269269
httptools==0.6.4
270270
# via uvicorn
271-
httpx==0.27.2
271+
httpx==0.28.1
272272
# via
273273
# -r requirements-constraints.txt
274274
# anthropic
@@ -700,7 +700,6 @@ sniffio==1.3.1
700700
# via
701701
# anthropic
702702
# anyio
703-
# httpx
704703
# openai
705704
sqlalchemy==2.0.25
706705
# via
@@ -730,7 +729,6 @@ threadpoolctl==3.2.0
730729
# scikit-learn
731730
tokenizers==0.15.2
732731
# via
733-
# anthropic
734732
# chromadb
735733
# transformers
736734
torch==2.2.0

src/seer/automation/agent/client.py

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import anthropic
88
from anthropic import NOT_GIVEN
99
from anthropic.types import (
10+
CacheControlEphemeralParam,
1011
MessageParam,
1112
TextBlockParam,
1213
ToolParam,
@@ -542,10 +543,22 @@ def _prep_message_and_tools(
542543
message_dicts = [cls.to_message_param(message) for message in messages] if messages else []
543544
if prompt:
544545
message_dicts.append(cls.to_message_param(Message(role="user", content=prompt)))
546+
# Set caching breakpoints for the last message and the 3rd last message
547+
if len(message_dicts) > 0 and message_dicts[-1]["content"]:
548+
message_dicts[-1]["content"][0]["cache_control"] = CacheControlEphemeralParam(
549+
type="ephemeral"
550+
)
551+
if len(message_dicts) >= 4 and message_dicts[-4]["content"]:
552+
message_dicts[-4]["content"][0]["cache_control"] = CacheControlEphemeralParam(
553+
type="ephemeral"
554+
)
545555

546556
tool_dicts = (
547557
[cls.to_tool_dict(tool) for tool in tools] if tools and len(tools) > 0 else None
548558
)
559+
# set caching breakpoint at end of tools
560+
if tool_dicts:
561+
tool_dicts[-1]["cache_control"] = CacheControlEphemeralParam(type="ephemeral")
549562

550563
return message_dicts, tool_dicts, system_prompt
551564

0 commit comments

Comments
 (0)