Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/session/runner/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,10 @@ export const layer = Layer.effect(
const model = yield* models.resolve(session)
const entries = yield* SessionHistory.entriesForRunner(db, session.id, system.baselineSeq)
const context = entries.map((entry) => entry.message)
const promptCacheKey = /^ses_[0-9a-f]{64}$/.test(session.id) ? session.id.slice(4) : session.id
const request = LLM.request({
model,
providerOptions: { openai: { promptCacheKey: session.id } },
providerOptions: { openai: { promptCacheKey } },
system: [agent.info?.system, system.baseline]
.filter((part): part is string => part !== undefined && part.length > 0)
.map(SystemPart.make),
Expand Down
36 changes: 36 additions & 0 deletions packages/core/test/session-runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2824,6 +2824,42 @@ describe("SessionRunnerLLM", () => {
}),
)

it.effect("bounds external session prompt cache keys", () =>
Effect.gen(function* () {
yield* setup
const externalSessionID = SessionV2.ID.fromExternal({
namespace: "discord",
key: "thread-one",
})
const otherExternalSessionID = SessionV2.ID.fromExternal({
namespace: "discord",
key: "thread-two",
})
yield* insertSession(externalSessionID)
yield* insertSession(otherExternalSessionID)
const session = yield* SessionV2.Service
yield* session.prompt({
sessionID: externalSessionID,
prompt: new Prompt({ text: "Run external session" }),
resume: false,
})
yield* session.prompt({
sessionID: otherExternalSessionID,
prompt: new Prompt({ text: "Run other external session" }),
resume: false,
})

requests.length = 0
yield* session.resume(externalSessionID)
yield* session.resume(otherExternalSessionID)

const keys = requests.map((request) => request.providerOptions?.openai?.promptCacheKey)
expect(keys).toEqual([externalSessionID.slice(4), otherExternalSessionID.slice(4)])
expect(keys.every((key) => typeof key === "string" && key.length === 64)).toBe(true)
expect(keys[0]).not.toBe(keys[1])
}),
)

it.effect("fans out one failed run and allows a later retry", () =>
Effect.gen(function* () {
yield* setup
Expand Down
Loading