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
29 changes: 29 additions & 0 deletions apps/docs/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4319,6 +4319,35 @@ export const ZaiIcon = (props: SVGProps<SVGSVGElement>) => (
</svg>
)

export function KieIcon(props: SVGProps<SVGSVGElement>) {
const id = useId()
const gradientId = `kie_gradient_${id}`

return (
<svg
{...props}
height='1em'
viewBox='0 -94.4 756.1 756.1'
width='1em'
xmlns='http://www.w3.org/2000/svg'
>
<title>Kie</title>
<defs>
<linearGradient id={gradientId} x1='0' y1='0' x2='0' y2='1'>
<stop offset='0' stopColor='#00A4F3' />
<stop offset='0.5' stopColor='#0C71D6' />
<stop offset='1' stopColor='#183DB8' />
</linearGradient>
</defs>
<path
fill={`url(#${gradientId})`}
fillRule='evenodd'
d='M318.7 8.7C298.7 12.2 284.4 23.6 272 46.1C268 53.3 257.2 72.8 247.9 89.6C238.6 106.4 228.6 124.6 225.6 130.1C222.7 135.6 215 149.3 208.6 160.6C197.3 180.4 169.4 230.3 144.1 276.1C137.4 288.2 122 315.6 109.9 337.1C97.8 358.5 82.2 386.4 75.1 399.1C59.1 427.7 59.6 427.1 52.8 430.3C43.8 434.5 31.9 447 26.8 457.6C8 497.2 27.4 541.3 68.6 552.3C88 557.5 111.1 552.4 126.6 539.6C134.3 533.3 131.3 533.6 184.6 533.6C226.7 533.6 234.2 533.4 237.4 532C252 525.9 255 507.2 243.1 496.8C236.8 491.2 237.3 491.3 192.9 491.5C146.4 491.8 149.6 492.4 149.6 483.8C149.6 464.8 133.3 439.3 115.9 431C109.3 427.9 108.3 426 111 422.1C115 416.3 202 260.9 241.2 189.6C267.2 142.2 280.3 119.2 281.5 118.8C282.1 118.6 285 120.5 287.8 123.1C293.4 128.1 301.1 132.4 309.4 135.1C313.3 136.4 314.6 137.3 314.6 138.8C314.6 139.8 307.9 152.5 299.7 166.9C291.6 181.3 278 205.2 269.6 220.1C261.2 234.9 244.8 264 233.1 284.6C221.4 305.2 202.7 338.5 191.6 358.6C180.4 378.7 167.9 400.7 163.9 407.5C155.4 421.6 153.5 426.1 153.5 432.7C153.4 441.3 159.9 449.9 168.5 452.4C173.6 454 276.4 454.1 281.9 452.5C286.9 451.1 293.1 445.4 296.1 439.5C297.4 437 299.2 434.6 300.1 434.2C303.5 432.9 457.1 433.5 458.9 434.8C460.4 436 487.8 484.2 501.5 510C509 524.1 512.4 528.1 519.1 531.2L524.1 533.6L572.9 533.6C624.8 533.6 623.6 533.5 629.1 538.7C647.6 556.1 681.6 559.3 704.6 545.9C747.3 520.9 748.1 459.5 705.9 432.2C698 427.1 697 425.9 690.6 414.1C688.3 409.7 676.1 388.1 663.6 366.1C643.9 331.4 623.1 294.1 590.6 235.1C586.1 226.8 569.7 197.4 554.3 169.6C468 14.2 473.4 23.4 464.8 17.4C454.2 10 455.5 10.2 391.6 9.4C360 9 331.9 8.5 329.1 8.2C326.4 8 321.7 8.2 318.7 8.7ZM340.5 51.5C358.8 60.9 358.1 87.2 339.3 95.1C318.1 103.9 298.7 79.3 311.2 59.4C317 50.3 330.8 46.6 340.5 51.5ZM468.3 102.6C501.2 160.9 535.9 223.3 553.6 255.6C560.4 268 571.2 287.3 577.6 298.6C609.7 355.1 647.8 424.7 647.3 426C647 426.8 644 428.9 640.6 430.7C622.3 440.5 609.4 460.3 607.8 481.6L607.1 490.1L597.6 490.7C579.5 492 543.1 491.7 541.3 490.3C540.4 489.7 534.5 479.9 528.3 468.6C486.5 392.7 489.6 397.7 481.9 394L476.1 391.1L381.1 390.8C316.3 390.6 284.6 390.9 281 391.6C273.3 393.2 267.2 397.5 263.5 404.1C261.7 407.4 259.5 409.8 258.3 410.1C257.1 410.4 246.1 410.5 233.9 410.4L211.7 410.1L228 381.6L244.3 353.1L339.2 352.6C429.3 352.1 434.3 352 437.6 350.2C445.9 345.8 450.8 338.4 450.8 330.4C450.8 324 450.2 322.6 436 297.6C429.3 285.8 416.2 262.4 406.8 245.6C397.5 228.8 381.3 199.8 370.9 181.1C360.4 162.4 350.9 145.2 349.8 142.9L347.6 138.7L358.4 133.5C386.8 119.9 401.9 89.8 395.1 60.7C392.8 50.9 391.3 51.5 417.2 51.8L439.8 52.1L468.3 102.6ZM335.8 206.4C337.8 209.5 344.1 220.6 349.9 231.1C355.6 241.5 366.8 261.6 374.8 275.6C389.1 300.6 393.6 309 393.6 310.1C393.6 310.4 365.7 310.6 331.6 310.6C287.9 310.6 269.6 310.3 269.6 309.5C269.6 308.9 281.8 286.8 296.7 260.4C328.9 203.4 330.5 200.6 331.4 200.6C331.8 200.6 333.8 203.2 335.8 206.4ZM92.6 465.6C105.2 469.1 112.1 485.5 106.2 498.1C98.2 515.4 73.1 516.3 64.4 499.7C54.4 480.5 71.6 459.7 92.6 465.6ZM681.9 465.9C700.3 473.7 700.5 501.3 682.1 509.7C673.5 513.7 660.4 510.9 654.4 503.8C644.1 491.6 648.5 472.3 663.1 466C667 464.3 677.8 464.2 681.9 465.9ZM418.1 126.5C405.8 129.6 398.1 142.2 401.8 153.1C402.6 155.3 412.7 173.7 424.2 194.1C435.8 214.4 451.5 242.4 459.1 256.3C466.7 270.1 474.2 283.1 475.8 285.1C487.2 298.8 509.8 293.5 513.7 276C515.6 267.5 517.2 270.8 470.1 187.6C461.2 171.9 451.6 154.8 448.7 149.6C441.6 136.6 437.3 131 432.9 128.7C428.3 126.4 422.1 125.5 418.1 126.5ZM525 326C517.6 329.5 512.6 337 512.6 344.9C512.6 348.7 518.9 362 529.8 381.1C534.5 389.3 543.7 406.2 550.2 418.4C556.7 430.7 563.6 442.6 565.5 444.8C577.7 459.1 601.9 452.7 604.3 434.7C605 429.5 603.4 425 596.6 413.1C589.6 400.9 571.4 367.9 561.6 349.6C552.6 332.9 549.9 329.4 543.4 326.2C536.9 323 531.6 322.9 525 326Z'
/>
</svg>
)
}

export const KimiIcon = (props: SVGProps<SVGSVGElement>) => (
<svg {...props} height='1em' viewBox='0 0 24 24' width='1em' xmlns='http://www.w3.org/2000/svg'>
<title>Kimi</title>
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/content/docs/workflows/blocks/agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ While an agent runs, Sim can stream its thinking and tool lifecycle live — the

{/* agent-stream-capabilities:begin — generated by `bun run agent-stream-docs:generate`; do not edit between markers */}

Live tool-call chips stream for **OpenAI, Anthropic, Azure Anthropic, Google, Vertex AI, DeepSeek, Groq, AWS Bedrock** models. Other providers run tools without live chips and project the settled final answer when the run completes; they do not ask the model to regenerate that answer just to create a stream.
Live tool-call chips stream for **OpenAI, Anthropic, Azure Anthropic, Google, Vertex AI, DeepSeek, Groq, Kie, AWS Bedrock** models. Other providers run tools without live chips and project the settled final answer when the run completes; they do not ask the model to regenerate that answer just to create a stream.

| Provider | Streamed thinking | Models |
|----------|-------------------|--------|
Expand All @@ -170,6 +170,7 @@ Live tool-call chips stream for **OpenAI, Anthropic, Azure Anthropic, Google, Ve
| Groq | Full thinking deltas | `groq/openai/gpt-oss-120b`, `groq/openai/gpt-oss-20b`, `groq/openai/gpt-oss-safeguard-20b`, `groq/qwen/qwen3.8-27b`, `groq/qwen/qwen3.6-27b` |
| Meta | Not streamed | `muse-spark-1.3`, `muse-spark-1.1` |
| Kimi | Full thinking deltas | `kimi-k3`, `kimi-k2.6` |
| Kie | Summaries only | `kie/claude-opus-5-5`, `kie/claude-opus-5`, `kie/claude-fable-5`, `kie/claude-sonnet-5`, `kie/claude-opus-4-8`, `kie/claude-opus-4-7`, `kie/claude-opus-4-6`, `kie/claude-sonnet-4-6`, `kie/claude-opus-4-5`, `kie/claude-sonnet-4-5`, `kie/claude-haiku-4-5`, `kie/gpt-6-astra`, `kie/gpt-6-sol`, `kie/gpt-6-luna`, `kie/gpt-5-6-sol`, `kie/gpt-5-6-terra`, `kie/gpt-5-6-luna`, `kie/gpt-5-5`, `kie/grok-4-6`, `kie/grok-4-5`, `kie/grok-4-3`, `kie/kimi-k3` |
| Z.ai | Full thinking deltas | `glm-5.3`, `glm-5.3-flash`, `glm-5.2`, `glm-5.1`, `glm-5`, `glm-5-turbo`, `glm-4.7`, `glm-4.6`, `glm-4.5`, `glm-4.5-air` |

{/* agent-stream-capabilities:end */}
Expand Down
1 change: 1 addition & 0 deletions apps/sim/app/(landing)/models/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const PROVIDER_PREFIXES: Record<string, string[]> = {
baseten: ['baseten/'],
'ollama-cloud': ['ollama-cloud/'],
groq: ['groq/'],
kie: ['kie/'],
openrouter: ['openrouter/'],
vllm: ['vllm/'],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
HunterIOIcon,
IcypeasIcon,
JinaAIIcon,
KieIcon,
KimiIcon,
LeadMagicIcon,
LinkupIcon,
Expand Down Expand Up @@ -166,6 +167,13 @@ const PROVIDERS: (BYOKManagerProvider & { id: BYOKProviderId })[] = [
description: 'LLM calls',
placeholder: 'Enter your Ollama API key',
},
{
id: 'kie',
name: 'Kie',
icon: KieIcon,
description: 'LLM calls',
placeholder: 'Enter your Kie API key',
},
{
id: 'falai',
name: 'Fal.ai',
Expand Down Expand Up @@ -365,6 +373,7 @@ const PROVIDER_SECTIONS: BYOKProviderSection[] = [
'together',
'baseten',
'ollama-cloud',
'kie',
'falai',
],
},
Expand Down
29 changes: 29 additions & 0 deletions apps/sim/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4319,6 +4319,35 @@ export const ZaiIcon = (props: SVGProps<SVGSVGElement>) => (
</svg>
)

export function KieIcon(props: SVGProps<SVGSVGElement>) {
const id = useId()
const gradientId = `kie_gradient_${id}`

return (
<svg
{...props}
height='1em'
viewBox='0 -94.4 756.1 756.1'
width='1em'
xmlns='http://www.w3.org/2000/svg'
>
<title>Kie</title>
<defs>
<linearGradient id={gradientId} x1='0' y1='0' x2='0' y2='1'>
<stop offset='0' stopColor='#00A4F3' />
<stop offset='0.5' stopColor='#0C71D6' />
<stop offset='1' stopColor='#183DB8' />
</linearGradient>
</defs>
<path
fill={`url(#${gradientId})`}
fillRule='evenodd'
d='M318.7 8.7C298.7 12.2 284.4 23.6 272 46.1C268 53.3 257.2 72.8 247.9 89.6C238.6 106.4 228.6 124.6 225.6 130.1C222.7 135.6 215 149.3 208.6 160.6C197.3 180.4 169.4 230.3 144.1 276.1C137.4 288.2 122 315.6 109.9 337.1C97.8 358.5 82.2 386.4 75.1 399.1C59.1 427.7 59.6 427.1 52.8 430.3C43.8 434.5 31.9 447 26.8 457.6C8 497.2 27.4 541.3 68.6 552.3C88 557.5 111.1 552.4 126.6 539.6C134.3 533.3 131.3 533.6 184.6 533.6C226.7 533.6 234.2 533.4 237.4 532C252 525.9 255 507.2 243.1 496.8C236.8 491.2 237.3 491.3 192.9 491.5C146.4 491.8 149.6 492.4 149.6 483.8C149.6 464.8 133.3 439.3 115.9 431C109.3 427.9 108.3 426 111 422.1C115 416.3 202 260.9 241.2 189.6C267.2 142.2 280.3 119.2 281.5 118.8C282.1 118.6 285 120.5 287.8 123.1C293.4 128.1 301.1 132.4 309.4 135.1C313.3 136.4 314.6 137.3 314.6 138.8C314.6 139.8 307.9 152.5 299.7 166.9C291.6 181.3 278 205.2 269.6 220.1C261.2 234.9 244.8 264 233.1 284.6C221.4 305.2 202.7 338.5 191.6 358.6C180.4 378.7 167.9 400.7 163.9 407.5C155.4 421.6 153.5 426.1 153.5 432.7C153.4 441.3 159.9 449.9 168.5 452.4C173.6 454 276.4 454.1 281.9 452.5C286.9 451.1 293.1 445.4 296.1 439.5C297.4 437 299.2 434.6 300.1 434.2C303.5 432.9 457.1 433.5 458.9 434.8C460.4 436 487.8 484.2 501.5 510C509 524.1 512.4 528.1 519.1 531.2L524.1 533.6L572.9 533.6C624.8 533.6 623.6 533.5 629.1 538.7C647.6 556.1 681.6 559.3 704.6 545.9C747.3 520.9 748.1 459.5 705.9 432.2C698 427.1 697 425.9 690.6 414.1C688.3 409.7 676.1 388.1 663.6 366.1C643.9 331.4 623.1 294.1 590.6 235.1C586.1 226.8 569.7 197.4 554.3 169.6C468 14.2 473.4 23.4 464.8 17.4C454.2 10 455.5 10.2 391.6 9.4C360 9 331.9 8.5 329.1 8.2C326.4 8 321.7 8.2 318.7 8.7ZM340.5 51.5C358.8 60.9 358.1 87.2 339.3 95.1C318.1 103.9 298.7 79.3 311.2 59.4C317 50.3 330.8 46.6 340.5 51.5ZM468.3 102.6C501.2 160.9 535.9 223.3 553.6 255.6C560.4 268 571.2 287.3 577.6 298.6C609.7 355.1 647.8 424.7 647.3 426C647 426.8 644 428.9 640.6 430.7C622.3 440.5 609.4 460.3 607.8 481.6L607.1 490.1L597.6 490.7C579.5 492 543.1 491.7 541.3 490.3C540.4 489.7 534.5 479.9 528.3 468.6C486.5 392.7 489.6 397.7 481.9 394L476.1 391.1L381.1 390.8C316.3 390.6 284.6 390.9 281 391.6C273.3 393.2 267.2 397.5 263.5 404.1C261.7 407.4 259.5 409.8 258.3 410.1C257.1 410.4 246.1 410.5 233.9 410.4L211.7 410.1L228 381.6L244.3 353.1L339.2 352.6C429.3 352.1 434.3 352 437.6 350.2C445.9 345.8 450.8 338.4 450.8 330.4C450.8 324 450.2 322.6 436 297.6C429.3 285.8 416.2 262.4 406.8 245.6C397.5 228.8 381.3 199.8 370.9 181.1C360.4 162.4 350.9 145.2 349.8 142.9L347.6 138.7L358.4 133.5C386.8 119.9 401.9 89.8 395.1 60.7C392.8 50.9 391.3 51.5 417.2 51.8L439.8 52.1L468.3 102.6ZM335.8 206.4C337.8 209.5 344.1 220.6 349.9 231.1C355.6 241.5 366.8 261.6 374.8 275.6C389.1 300.6 393.6 309 393.6 310.1C393.6 310.4 365.7 310.6 331.6 310.6C287.9 310.6 269.6 310.3 269.6 309.5C269.6 308.9 281.8 286.8 296.7 260.4C328.9 203.4 330.5 200.6 331.4 200.6C331.8 200.6 333.8 203.2 335.8 206.4ZM92.6 465.6C105.2 469.1 112.1 485.5 106.2 498.1C98.2 515.4 73.1 516.3 64.4 499.7C54.4 480.5 71.6 459.7 92.6 465.6ZM681.9 465.9C700.3 473.7 700.5 501.3 682.1 509.7C673.5 513.7 660.4 510.9 654.4 503.8C644.1 491.6 648.5 472.3 663.1 466C667 464.3 677.8 464.2 681.9 465.9ZM418.1 126.5C405.8 129.6 398.1 142.2 401.8 153.1C402.6 155.3 412.7 173.7 424.2 194.1C435.8 214.4 451.5 242.4 459.1 256.3C466.7 270.1 474.2 283.1 475.8 285.1C487.2 298.8 509.8 293.5 513.7 276C515.6 267.5 517.2 270.8 470.1 187.6C461.2 171.9 451.6 154.8 448.7 149.6C441.6 136.6 437.3 131 432.9 128.7C428.3 126.4 422.1 125.5 418.1 126.5ZM525 326C517.6 329.5 512.6 337 512.6 344.9C512.6 348.7 518.9 362 529.8 381.1C534.5 389.3 543.7 406.2 550.2 418.4C556.7 430.7 563.6 442.6 565.5 444.8C577.7 459.1 601.9 452.7 604.3 434.7C605 429.5 603.4 425 596.6 413.1C589.6 400.9 571.4 367.9 561.6 349.6C552.6 332.9 549.9 329.4 543.4 326.2C536.9 323 531.6 322.9 525 326Z'
/>
</svg>
)
}

export const KimiIcon = (props: SVGProps<SVGSVGElement>) => (
<svg {...props} height='1em' viewBox='0 0 24 24' width='1em' xmlns='http://www.w3.org/2000/svg'>
<title>Kimi</title>
Expand Down
2 changes: 2 additions & 0 deletions apps/sim/ee/organization-usage/components/usage-consumers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
FireworksIcon,
GeminiIcon,
GroqIcon,
KieIcon,
KimiIcon,
LitellmIcon,
MetaIcon,
Expand Down Expand Up @@ -64,6 +65,7 @@ const PROVIDER_ICONS: Readonly<Record<string, ComponentType<{ className?: string
fireworks: FireworksIcon,
google: GeminiIcon,
groq: GroqIcon,
kie: KieIcon,
kimi: KimiIcon,
litellm: LitellmIcon,
meta: MetaIcon,
Expand Down
14 changes: 14 additions & 0 deletions apps/sim/lib/api-key/byok.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ export async function getApiKeyWithBYOK(
throw new Error(`API key is required for Ollama Cloud ${model}`)
}

if (provider === 'kie') {
if (workspaceId) {
const byokResult = await getBYOKKey(workspaceId, 'kie')
if (byokResult) {
logger.info('Using BYOK key for Kie', { model, workspaceId, scope: byokResult.scope })
return byokResult
}
}
if (userProvidedKey) {
return { apiKey: userProvidedKey, isBYOK: false }
}
throw new Error(`API key is required for Kie ${model}`)
}

if (provider === 'bedrock') {
return { apiKey: PROVIDER_PLACEHOLDER_KEY, isBYOK: false }
}
Expand Down
1 change: 1 addition & 0 deletions apps/sim/lib/api/contracts/byok-keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const byokProviderIdSchema = z.enum([
'together',
'baseten',
'ollama-cloud',
'kie',
'falai',
'firecrawl',
'exa',
Expand Down
7 changes: 3 additions & 4 deletions apps/sim/lib/memory/agent-turn-session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import {
projectResolvedSecretModelJsonStrings,
} from '@/executor/utils/resolved-secret-content-projection'
import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
import { providerHistoryProtocols } from '@/providers/history-adapters'
import { getProviderHistoryProtocol, isHistoryProviderId } from '@/providers/history-adapters'

const logger = createLogger('AgentMemory')
const MAX_CACHED_AGENT_TURNS = 32
Expand Down Expand Up @@ -183,7 +183,7 @@ function validState(value: unknown): value is AgentTurnState {
if (
!isRecordLike(native) ||
typeof native.providerId !== 'string' ||
!Object.hasOwn(providerHistoryProtocols, native.providerId) ||
!isHistoryProviderId(native.providerId) ||
typeof native.model !== 'string' ||
!native.model ||
typeof native.binding !== 'string' ||
Expand All @@ -193,8 +193,7 @@ function validState(value: unknown): value is AgentTurnState {
(typeof native.prefixHash !== 'string' || !/^[a-f0-9]{64}$/.test(native.prefixHash)))
)
return false
const protocol =
providerHistoryProtocols[native.providerId as keyof typeof providerHistoryProtocols]
const protocol = getProviderHistoryProtocol(native.providerId, native.model)
if (
native.protocol !== protocol &&
!(native.providerId === 'azure-openai' && native.protocol === 'chat-completions')
Expand Down
5 changes: 5 additions & 0 deletions apps/sim/lib/tokenization/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ export const TOKENIZATION_CONFIG = {
confidence: 'medium',
supportedMethods: ['heuristic', 'fallback'],
},
kie: {
avgCharsPerToken: 4,
confidence: 'medium',
supportedMethods: ['heuristic', 'fallback'],
},
ollama: {
avgCharsPerToken: 4,
confidence: 'low',
Expand Down
5 changes: 3 additions & 2 deletions apps/sim/providers/anthropic/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ async function createMessage(
)
return stream.finalMessage()
}
// Explicit `stream: false`: Anthropic-compatible proxies (Kie) treat an absent flag as true.
return anthropic.messages.create(
payload as Anthropic.Messages.MessageCreateParamsNonStreaming,
{ ...(payload as Anthropic.Messages.MessageCreateParamsNonStreaming), stream: false },
options
) as Promise<Anthropic.Messages.Message>
)
}

/**
Expand Down
6 changes: 3 additions & 3 deletions apps/sim/providers/conversation-continuation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
retainCompatibleNativeConversationMessage,
setNativeConversationMessage,
} from '@/providers/conversation-metadata'
import { providerHistoryProtocols, requiresNativeToolHistory } from '@/providers/history-adapters'
import { getProviderHistoryProtocol, requiresNativeToolHistory } from '@/providers/history-adapters'
import { executeProviderTool } from '@/providers/runtime-context'
import { isAbortError } from '@/providers/streaming-tool-loop-shared'
import type { Message, ProviderId, ProviderRequest } from '@/providers/types'
Expand Down Expand Up @@ -139,7 +139,7 @@ export async function restoreConversationNativeMessages(
providerId === 'azure-openai' &&
isChatCompletionsEndpoint(request?.azureEndpoint || env.AZURE_OPENAI_ENDPOINT || '')
? 'chat-completions'
: providerHistoryProtocols[providerId]
: getProviderHistoryProtocol(providerId, model)
if (!protocol) throw new Error('Evaluation providers do not support conversation history')
const restored: Message[] = []
for (const group of groupConversationMessages(messages)) {
Expand Down Expand Up @@ -178,7 +178,7 @@ export async function restoreConversationNativeMessages(
if (
first.tool_calls?.length &&
!getNativeConversationMessage(first, protocol) &&
requiresNativeToolHistory(providerId)
requiresNativeToolHistory(providerId, model)
) {
logger.info('Agent memory used portable execution history', { protocol })
restored.push(renderConversationExecutionRecord(group))
Expand Down
2 changes: 1 addition & 1 deletion apps/sim/providers/history-adapters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('canonical provider wire adapters', () => {
expect(
PROVIDER_DEFINITIONS[providerId].models.every((model) => isEvaluationModel(model.id))
).toBe(true)
} else {
} else if (typeof protocol !== 'function') {
expect(providerHistoryAdapters[protocol]).toBeDefined()
}
}
Expand Down
30 changes: 28 additions & 2 deletions apps/sim/providers/history-adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
CapturedConversationStep,
ConversationProtocol,
} from '@/lib/memory/conversation-types'
import { getKieConversationProtocol, isKieClaudeModel } from '@/providers/kie/utils'
import type { ProviderId } from '@/providers/types'

export interface ProviderHistoryAdapter {
Expand Down Expand Up @@ -80,7 +81,15 @@ export const providerHistoryAdapters: Record<ConversationProtocol, ProviderHisto
bedrock: { protocol: 'bedrock', capture: (value) => capture('bedrock', value) },
}

export const providerHistoryProtocols: Record<ProviderId, ConversationProtocol | null> = {
/**
* Native history protocol per provider. `null` marks evaluation-only providers; a function
* resolves per model for providers that proxy more than one wire protocol. Read it through
* {@link getProviderHistoryProtocol}.
*/
export const providerHistoryProtocols: Record<
ProviderId,
ConversationProtocol | null | ((model: string) => ConversationProtocol)
> = {
openai: 'responses',
'azure-openai': 'responses',
anthropic: 'anthropic',
Expand All @@ -98,6 +107,7 @@ export const providerHistoryProtocols: Record<ProviderId, ConversationProtocol |
meta: 'chat-completions',
zai: 'chat-completions',
kimi: 'chat-completions',
kie: getKieConversationProtocol,
mistral: 'chat-completions',
ollama: 'chat-completions',
'ollama-cloud': 'chat-completions',
Expand All @@ -109,9 +119,25 @@ export const providerHistoryProtocols: Record<ProviderId, ConversationProtocol |
litellm: 'chat-completions',
}

export function isHistoryProviderId(value: string): value is ProviderId {
return Object.hasOwn(providerHistoryProtocols, value)
}

export function getProviderHistoryProtocol(
providerId: ProviderId,
model: string
): ConversationProtocol | null {
const protocol = providerHistoryProtocols[providerId]
return typeof protocol === 'function' ? protocol(model) : protocol
}

/** Bedrock is treated conservatively because its Claude models also require signed thinking. */
export function requiresNativeToolHistory(providerId: ProviderId | undefined): boolean {
export function requiresNativeToolHistory(
providerId: ProviderId | undefined,
model: string
): boolean {
return (
(providerId === 'kie' && isKieClaudeModel(model)) ||
providerId === 'anthropic' ||
providerId === 'azure-anthropic' ||
providerId === 'bedrock' ||
Expand Down
Loading
Loading