Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
eca74d6
Add initial skill for testing, which is simply Steve's skill (#1)
donald-pinckney Feb 2, 2026
5998c64
Use claude to merge Steve's, Max's, and Mason's skills. (#2)
donald-pinckney Feb 4, 2026
ff033bc
add simple feedback mechanism (#3)
donald-pinckney Feb 4, 2026
b8b74c0
Change skill name to kebab-case, for compatibility with Amp and Cline…
donald-pinckney Feb 13, 2026
d25073a
Clean up references/core/ai-integration.md
donald-pinckney Feb 13, 2026
b0fcfe3
Clean up references/core/common-gotchas.md
donald-pinckney Feb 13, 2026
e113399
Clean up references/core/common-gotchas.md
donald-pinckney Feb 13, 2026
2b6676f
Clean up references/core/determinism.md
donald-pinckney Feb 13, 2026
efc8ef2
Clean up references/core/determinism.md
donald-pinckney Feb 13, 2026
45497f4
Update error-reference.md
donald-pinckney Feb 17, 2026
f61d2ea
Update interactive-workflows.md
donald-pinckney Feb 17, 2026
1f4c53d
Clean up patterns.md
donald-pinckney Feb 17, 2026
3c19991
Cut shell scripts
donald-pinckney Feb 17, 2026
d237247
Edit troubleshooting.md
donald-pinckney Feb 17, 2026
5695854
remove interceptors for now
donald-pinckney Feb 18, 2026
e10cbb8
remove dynamic workflows
donald-pinckney Feb 18, 2026
d4d9921
clarify on heartbeating of async activity completions, and prompt it …
donald-pinckney Feb 18, 2026
1c185b6
Improve references/python/advanced-features.md
donald-pinckney Feb 18, 2026
e945f1d
Use explicit namespace in connect
donald-pinckney Feb 18, 2026
322f85a
remove duplicated content from determinism.md, clean up
donald-pinckney Feb 18, 2026
bb46cb4
Improve references/python/data-handling.md
donald-pinckney Feb 18, 2026
3dcccb8
Prefer start_to_close_timeout
donald-pinckney Feb 18, 2026
8b7dffa
don't explicitely provide defaults for retry policies
donald-pinckney Feb 18, 2026
f693cc7
error-handling.md cleanup
donald-pinckney Feb 18, 2026
3d43cd2
move idempotency patterns to patterns.md
donald-pinckney Feb 18, 2026
f0387e3
remove multi-param activities
donald-pinckney Feb 18, 2026
f36faca
small edits
donald-pinckney Feb 18, 2026
0bc69b2
Unify sandbox stuff into one file
donald-pinckney Feb 18, 2026
56dde75
local activities aren't experimental
donald-pinckney Feb 18, 2026
35c3bc5
Clean up references/python/sync-vs-async.md
donald-pinckney Feb 18, 2026
d61866b
Cleanup observability.md, remove duplicated search attributes
donald-pinckney Feb 19, 2026
ad4cc34
Cut otel for now
donald-pinckney Feb 19, 2026
f01763a
cut a lot of duplicate stuff from python gotchas, address comments
donald-pinckney Feb 20, 2026
cbfd857
de-duplicate content
donald-pinckney Feb 20, 2026
79ecaf3
Lots of improvements to testing
donald-pinckney Feb 20, 2026
663bbe4
cleanup to top level of skill (like CLI install instructions), and to…
donald-pinckney Feb 20, 2026
ec02f38
Improve patterns.md
donald-pinckney Feb 23, 2026
14da16a
clean up ai-patterns.md
donald-pinckney Feb 23, 2026
fd1af23
Update readme with installation instructions
donald-pinckney Feb 23, 2026
846cb44
remove ts directory
donald-pinckney Feb 23, 2026
0692311
De-couple core from python and TypeScript as much as possible
donald-pinckney Feb 23, 2026
83aa233
Remove TypeScript hints
donald-pinckney Feb 23, 2026
47ae2fd
add prompting for feedback at startup - wait for ethan on slack channel
donald-pinckney Feb 19, 2026
75c568d
shorten url
donald-pinckney Feb 19, 2026
3f972f9
Update slack channel
donald-pinckney Feb 23, 2026
99a2d4a
Automated pass over on python cleanup & deduplication
donald-pinckney Feb 27, 2026
87fe92e
Remove multi-patching from Python, since its obvious, dont waste toke…
donald-pinckney Mar 3, 2026
766f888
Add TypeScript (#31)
donald-pinckney Mar 7, 2026
8ad9233
Fix typos and reference links (#36)
donald-pinckney Mar 7, 2026
c73c9c0
quick edit to readme (#37)
donald-pinckney Mar 12, 2026
c013b87
Fix saga compensations to run under cancellation protection (#43)
donald-pinckney Mar 17, 2026
291f4e5
Update readme for public preview (#45)
donald-pinckney Mar 18, 2026
21d1d41
a few more readme tweaks (#46)
donald-pinckney Mar 18, 2026
6cd40f2
Add MIT License to the project (#47)
donald-pinckney Mar 18, 2026
e16c9b8
Add Go (supersedes other PR) (#38)
donald-pinckney Mar 19, 2026
b9a0728
Setup CODEOWNERS to AI SDK team (#48)
donald-pinckney Mar 19, 2026
29e4600
Align version number in SKILL.md and plugin.json. (#49)
donald-pinckney Mar 19, 2026
1cc4591
Merge branch 'main' into dev
donald-pinckney Mar 19, 2026
68ebe14
Fix typos and broken references across skill docs (#56)
jacksonlo Mar 31, 2026
b040ae1
Fix Python reference bugs: incorrect API name, syntax error, broken c…
trevoryao Mar 31, 2026
57c08ef
Add `@workflow.init` decorator to python.md Key Concepts (#57)
brianstrauch Mar 31, 2026
8369c65
Remove ASCII diagram, replace with prose. (#66)
donald-pinckney Apr 2, 2026
9b97cee
[fix] Add missing section to TS's observability (#65)
donald-pinckney Apr 2, 2026
0c8586b
Add Java SDK support (#42)
donald-pinckney Apr 2, 2026
7d5ae76
Reduce repetition in determinism sans sandboxing (#67)
donald-pinckney Apr 2, 2026
25eb553
Bump to 0.2.0 for Java release (#72)
donald-pinckney Apr 3, 2026
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
Prev Previous commit
Next Next commit
Clean up references/core/ai-integration.md
  • Loading branch information
donald-pinckney committed Feb 19, 2026
commit d25073a47e8c35d59d9ad878bd65c01906a2a052
133 changes: 39 additions & 94 deletions references/core/ai-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

Temporal provides durable execution for AI/LLM applications, handling retries, rate limits, and long-running operations automatically. These patterns apply across languages, with Python being the most mature for AI integration.

For Python-specific implementation details and code examples, see `references/python/ai-patterns.md`.
For Python-specific implementation details and code examples, see `references/python/ai-patterns.md`. Temporal's Python SDK also provides pre-built integrations with several LLM and agent SDKs, which can be leveraged to create agentic workflows with minimal effort (when working in Python).

The remainder of this document describes general principles to follow when building AI/LLM applications in Temporal, particularly when from scratch instead of with an integration.

## Why Temporal for AI?

Expand All @@ -19,28 +21,24 @@ For Python-specific implementation details and code examples, see `references/py

## Core Patterns

### Pattern 1: Generic LLM Activity

Create flexible, reusable activities for LLM calls:
### Pattern 1: Activities should Wrap LLM Calls

```
Activity: call_llm_generic(
model: string,
system_instructions: string,
user_input: string,
tools?: list,
response_format?: schema
) -> response
```
- activity: call_llm
- inputs:
- model_id -> internally activity can route to different models, so we don't need 1 activity per unique model.
- prompt / chat history
- tools
- etc.
- returns model response, as a typed structured output

**Benefits**:
- Single activity handles multiple use cases
- Consistent retry handling
- Centralized configuration

### Pattern 2: Activity-Based Separation
### Pattern 2: Non-deterministic / heavy tools in Activities

Isolate each operation in its own activity:
Tools which are non-deterministic and/or heavy actions (file system, hitting APIs, etc.) should be placed in activities:

```
Workflow:
Expand All @@ -55,55 +53,32 @@ Workflow:
- Easier testing and mocking
- Failure isolation

### Pattern 3: Centralized Retry Management
### Pattern 3: Tools that Mutate Agent State can be in the Workflow directly

**Critical**: Disable retries in LLM client libraries, let Temporal handle retries.
Generally, agent state is in bijection with workflow state. Thus, tools which mutate agent state and are deterministic (like TODO tools, just updating a hash map) typically belong in the workflow code rather than an activity.

```
LLM Client Config:
max_retries = 0 ← Disable client retries

Activity Retry Policy:
initial_interval = 1s
backoff_coefficient = 2.0
maximum_attempts = 5
maximum_interval = 60s
Workflow:
├── Activity: call_llm (tool selection: todos_write tool)
├── Write new TODOs to workflow state (not in activity)
└── Activity: call_llm (continuing agent flow...)
```

### Pattern 4: Centralized Retry Management

Disable retries in LLM client libraries, let Temporal handle retries.

- LLM Client Config:
- max_retries = 0 ← Disable client retries at the LLM client level

Use either the default activity retry policy, or customize it as needed for the situation.

**Why**:
- Temporal retries are durable (survive crashes)
- Single retry configuration point
- Better visibility into retry attempts
- Consistent backoff behavior

### Pattern 4: Tool-Calling Agent

Three-phase workflow for LLM agents with tools:

```
┌─────────────────────────────────────────────┐
│ Phase 1: Tool Selection │
│ Activity: Present tools to LLM │
│ LLM returns: tool_name, arguments │
└─────────────────────────────────────────────┘
┌─────────────────────────────────────────────┐
│ Phase 2: Tool Execution │
│ Activity: Execute selected tool │
│ (Separate activity per tool type) │
└─────────────────────────────────────────────┘
┌─────────────────────────────────────────────┐
│ Phase 3: Result Interpretation │
│ Activity: Send results back to LLM │
│ LLM returns: final response or next tool │
└─────────────────────────────────────────────┘
Loop until LLM returns final answer
```

### Pattern 5: Multi-Agent Orchestration

Expand All @@ -127,21 +102,6 @@ Deep Research Example:

**Key Pattern**: Use parallel execution with `return_exceptions=True` to continue with partial results when some searches fail.

### Pattern 6: Structured Outputs

Define schemas for LLM responses:

```
Input: Raw LLM prompt
Schema: { action: string, confidence: float, reasoning: string }
Output: Validated, typed response
```

**Benefits**:
- Type safety
- Automatic validation
- Easier downstream processing

## Timeout Recommendations

| Operation Type | Recommended Timeout |
Expand All @@ -165,27 +125,14 @@ Output: Validated, typed response

Parse rate limit info from API responses:

```
Response Headers:
Retry-After: 30
X-RateLimit-Remaining: 0

Activity:
If rate limited:
Raise retryable error with retry_after hint
Temporal handles the delay
```

### Retry Policy Configuration
- Response Headers:
- Retry-After: 30
- X-RateLimit-Remaining: 0

```
Retry Policy:
initial_interval: 1s (or from Retry-After header)
backoff_coefficient: 2.0
maximum_interval: 60s
maximum_attempts: 10
non_retryable_errors: [InvalidAPIKey, InvalidInput]
```
- Activity:
- If rate limited:
- Raise retryable error with retry_after hint
- Temporal handles the delay

## Error Handling

Expand All @@ -209,15 +156,13 @@ Retry Policy:
4. **Use structured outputs** - For type safety and validation
5. **Handle partial failures** - Continue with available results
6. **Monitor costs** - Track LLM calls at activity level
7. **Version prompts** - Track prompt changes in code
8. **Test with mocks** - Mock LLM responses in tests
7. **Test with mocks** - Mock LLM responses in tests

## Observability

- **Activity duration**: Track LLM latency
- **Retry counts**: Monitor rate limiting
- **Token usage**: Log in activity output
- **Cost attribution**: Tag workflows with cost centers
See `references/python/observability.md` (or the language you are working in) for documentation on observability in Temporal. It is generally recommended to add observability for:
- Token usage, via activity logging
- any else to help track LLM usage and debug agentic flows, within moderation.

## Language-Specific Resources

Expand Down