Skip to content

Commit 8d58d6f

Browse files
authored
Merge pull request #77 from openai/quickstart-and-ia-updates
[docs] Added Quick start; flattened and consolidated guides
2 parents 799d42f + e8c8783 commit 8d58d6f

37 files changed

Lines changed: 2391 additions & 1474 deletions

docs/concepts/actions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ When you set `handler: "client"`, the action flows into the client SDK’s `widg
1919
Your client integration can also initiate actions directly with `chatkit.sendCustomAction(action, itemId?)`, optionally namespaced to a specific widget item. The server receives these in `ChatKitServer.action` just like a widget-triggered action and can stream widgets, messages, or client effects in response. This pattern is useful when a flow starts outside a widget—or after a client-handled action—but you still want the server to persist results or involve the model.
2020

2121
## Related guides
22-
- [Handle widget actions](../guides/add-features/handle-widget-actions.md)
22+
- [Build interactive responses with widgets](../guides/build-interactive-responses-with-widgets.md)

docs/concepts/entities.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Entities can be used as cited sources in assistant responses.
1717
**References:**
1818

1919
- The [EntitySource](../../api/chatkit/types/#chatkit.types.EntitySource) Pydantic model definition
20-
- [Add annotations in assistant messages](../guides/add-features/add-annotations.md#annotating-with-custom-entities).
20+
- [Add annotations in assistant messages](../guides/add-annotations.md#annotating-with-custom-entities).
2121

2222
## Entity tags as @-mentions in user messages
2323

@@ -27,4 +27,4 @@ Users can tag your entities in the composer using @-mentions.
2727

2828
- The [Entity](https://openai.github.io/chatkit-js/api/openai/chatkit-react/type-aliases/entity/) TypeScript type definition
2929
- The [UserMessageTagContent](../../api/chatkit/types/#chatkit.types.UserMessageTagContent) Pydantic model definition
30-
- [Allow @-mentions in user messages](../guides/add-features/allow-mentions.md).
30+
- [Accept rich user input](../guides/accept-rich-user-input.md#-mentions-tag-entities-in-user-messages).

docs/concepts/thread-items.md

Lines changed: 0 additions & 54 deletions
This file was deleted.

docs/concepts/thread-stream-events.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ Stream [`ErrorEvent`](../../api/chatkit/types/#chatkit.types.ErrorEvent)s for us
2929

3030
Stream [`ProgressUpdateEvent`](../../api/chatkit/types/#chatkit.types.ProgressUpdateEvent)s to show the user transient status while work is in flight.
3131

32-
See [Show progress for long-running tools](../guides/add-features/show-progress-for-long-running-tools.md) for more info.
32+
See [Show progress while tools run](../guides/update-client-during-response.md#show-progress-while-tools-run) for more info.
3333

3434
## Client effects
3535

3636
Use [`ClientEffectEvent`](../../api/chatkit/types/#chatkit.types.ClientEffectEvent) to trigger fire-and-forget behavior on the client such as opening a dialog or pushing updates.
3737

38-
See [Send client effects](../guides/add-features/send-client-effects.md) for more info.
38+
See [Trigger client-side effects without blocking](../guides/update-client-during-response.md#trigger-client-side-effects-without-blocking) for more info.
3939

4040
## Stream options
4141

4242
[`StreamOptionsEvent`](../../api/chatkit/types/#chatkit.types.StreamOptionsEvent) configures runtime stream behavior (for example, allowing user cancellation). `ChatKitServer` emits one at the start of every stream using `get_stream_options`; override that method to change defaults such as `allow_cancel`.
4343

4444

4545
## Related guides
46-
- [Stream responses back to your user](../guides/stream-thread-events.md)
46+
- [Respond to a user message](../guides/respond-to-user-message.md)

docs/concepts/threads.md

Lines changed: 118 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,123 @@
1-
# Threads
1+
# Threads and items
22

3-
Threads are the core unit of ChatKit: a single conversation timeline that groups messages, tool calls, widgets, and related metadata.
3+
In ChatKit, a **thread** represents a single conversation. It is the unit that ties together everything that happens in that conversation: messages, widgets, actions, system signals, and metadata. A thread is stored as an ordered history of **thread items**, which ChatKit loads, paginates, and renders as needed.
44

5-
## Lifecycle
6-
- When a user submits a message and no thread exists, `ChatKitServer` creates one by calling your store's [`save_thread`](../../api/chatkit/store/#chatkit.store.Store.save_thread).
7-
- As responses stream back, `ChatKitServer` automatically persists thread items as they are completed—see [Thread items](thread-items.md) and [Stream responses back to your user](../guides/stream-thread-events.md) for how events drive storage.
8-
- Update titles or metadata intentionally in your integration (e.g., after summarizing a topic) by calling [`store.save_thread`](../../api/chatkit/store/#chatkit.store.Store.save_thread) with the new values.
9-
- When history is enabled client-side, ChatKit retrieves past threads. The user can continue any previous thread by default.
10-
- Archive or close threads according to your policies: mark them read-only (e.g., [disable new messages](../guides/add-features/disable-new-messages.md)) or delete them if you no longer want them discoverable.
5+
## What is a thread?
116

7+
A thread is an ordered timeline that contains:
8+
9+
- Conversation history (user and assistant messages)
10+
- Structured content such as widgets and workflows
11+
- Internal signals that guide processing or model behavior
12+
- Metadata like titles or status flags
13+
14+
Threads are persisted by your store implementation and can be updated, continued, or made read-only according to your application’s needs.
15+
16+
## What are thread items?
17+
18+
Thread items are the individual records that make up a thread. Each item represents one meaningful unit in the conversation history, such as:
19+
20+
- A user message
21+
- An assistant response
22+
- A widget rendered by the assistant
23+
- A non-visible signal used only for model input
24+
25+
ChatKit maintains the order of items, streams new ones as they are produced, and paginates them when history is loaded.
26+
27+
## How threads are created and updated
28+
29+
A typical thread lifecycle looks like this:
30+
31+
- **Thread creation**: When a user submits a message and no thread exists yet, ChatKitServer creates one and persists it by calling your store’s `save_thread`.
32+
- **Appending items**: As the server streams a response, ChatKit persists thread items automatically as each item completes. Streaming events directly drive what gets stored.
33+
- **Updating metadata**: During respond, you can freely mutate the thread object (for example, to set or refine the title). ChatKit automatically persists these updates when the response completes. You can also call store.save_thread explicitly if needed.
34+
- **Loading history**: When history is enabled client-side, ChatKit retrieves past threads and their items. Users can continue an existing thread by default.
35+
- **Closing or archiving**: Threads can be marked read-only (for example, by disabling new messages) or deleted entirely if they should no longer be discoverable.
36+
37+
38+
## How thread items are used
39+
40+
Thread items serve two primary purposes in ChatKit:
41+
42+
### Model input
43+
44+
Your server's [`respond`](../../api/chatkit/server/#chatkit.server.ChatKitServer.respond) logic reads thread items to construct input for the model input. This ensures the model sees the full conversational context both during an active response and when a user resumes a past thread.
45+
46+
See [Respond to a user message](../guides/respond-to-user-message.md) for a full walkthrough.
47+
48+
### UI rendering
49+
50+
On the client, ChatKit.js renders items incrementally as they stream in for the active thread. When a past thread is loaded, the same persisted items are re-rendered to reconstruct the conversation UI.
51+
52+
## Core item types
53+
54+
### User messages
55+
56+
[`UserMessageItem`](../../api/chatkit/types/#chatkit.types.UserMessageItem)s represent end-user input. They may include:
57+
58+
- Plain text entered by the user
59+
- Optional `quoted_text` for reply-style UIs
60+
- Attachment metadata
61+
62+
63+
User text is not Markdown-rendered, but it may contain [@-mentions](../guides/accept-rich-user-input.md#-mentions-tag-entities-in-user-messages) if your integration enables them.
64+
65+
66+
### Assistant messages
67+
68+
[`AssistantMessageItem`](../../api/chatkit/types/#chatkit.types.AssistantMessageItem)s represent assistant output. Their content can include:
69+
70+
- Markdown-rendered text
71+
- Tool call outputs
72+
- Widgets and structured UI elements
73+
- [Inline annotations](../guides/add-annotations.md)
74+
75+
Assistant text supports rich Markdown and is rendered progressively as it streams.
76+
77+
#### Markdown support
78+
79+
Assistant messages support:
80+
81+
- GitHub-flavored Markdown (headings, lists, code blocks, links, blockquotes)
82+
- Stable list rendering during streaming (Safari-safe, no reflow)
83+
- Optional single-newline line breaks
84+
- Syntax-highlighted, copyable code blocks
85+
- LaTeX math (inline and block)
86+
- Tables with automatic sizing and horizontal scrolling
87+
- Inline annotations that create interactive affordances in the UI
88+
89+
### Hidden context items
90+
91+
Hidden context items are included in model input but are not rendered in the chat UI. They allow the model to react to what happened in the interface, not just what the user typed.
92+
93+
Typical use cases include recording widget actions, selection state, or system signals.
94+
95+
- **[`HiddenContextItem`](../../api/chatkit/types/#chatkit.types.HiddenContextItem)**: Integration-defined hidden context. You control its schema and how it is converted for the model.
96+
97+
- **[`SDKHiddenContextItem`](../../api/chatkit/types/#chatkit.types.SDKHiddenContextItem)**: Hidden context inserted by the ChatKit Python SDK for its own internal operations. Most applications do not need to modify this unless overriding conversion behavior.
98+
99+
## Thread item actions
100+
101+
Thread item actions are quick action buttons associated with an assistant turn. They let users act on the output—such as retrying a response, copying content, or submitting feedback.
102+
103+
Actions are configured client-side using the [threadItemActions option](https://openai.github.io/chatkit-js/api/openai/chatkit-react/type-aliases/threaditemactionsoption/).
104+
105+
## Converting items to model input
106+
107+
[`ThreadItemConverter`](../../api/chatkit/agents/#chatkit.agents.ThreadItemConverter) translates stored thread items into model-ready input items. The default converter understands common ChatKit item types such as messages, widgets, workflows, and tasks.
108+
109+
You can override the converter when you need custom behavior. For example:
110+
111+
- Formatting attachments for the model
112+
- Translating tags or mentions into structured input
113+
- Summarizing rich widgets into text the model can consume
114+
115+
Custom conversion is typically paired with prompting so the model receives a coherent representation of the conversation.
12116

13117
## Related guides
14-
- [Persist ChatKit threads and messages](../guides/persist-chatkit-data.md)
15-
- [Save thread titles](../guides/add-features/save-thread-titles.md)
16-
- [Disable new messages for a thread](../guides/add-features/disable-new-messages.md)
118+
- [Respond to a user message](../guides/respond-to-user-message.md)
119+
- [Pass extra app context to your model](../guides/pass-extra-app-context-to-your-model.md)
120+
- [Add annotations in assistant messages](../guides/add-annotations.md)
121+
- [Accept rich user input](../guides/accept-rich-user-input.md#-mentions-tag-entities-in-user-messages)
122+
- [Handle feedback](../guides/handle-feedback.md)
123+
- [Let users browse past threads](../guides/browse-past-threads.md)

docs/concepts/tools.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Tools
2+
3+
Tools let the assistant call into your application logic during a turn—for example to search data, run a workflow, or fetch the user’s current context—then feed the results back into the model.
4+
5+
At a high level:
6+
7+
- **Server tools** run on your backend. The assistant calls them through your inference pipeline, and you stream their results back into the conversation.
8+
- **Client tools** run in the browser or host app. ChatKit surfaces a tool call as a streamed thread item, lets the client handle it, then resumes the conversation with the tool’s output.
9+
10+
## Server tools
11+
12+
Server tools are ordinary Python functions you register with your inference setup (for example, as tools on an agent or as explicit steps in your pipeline). During inference, the model can decide to call them; ChatKit serializes the call, runs your function, and feeds the output back to the model.
13+
14+
Use server tools to:
15+
16+
- Look up data in your own APIs or databases.
17+
- Kick off long-running jobs while streaming progress updates.
18+
- Update your own domain state (tickets, orders, files, etc.) in response to a turn.
19+
20+
From the model’s perspective, tools are structured, named capabilities it can invoke instead of guessing from free text.
21+
22+
## Client tools
23+
24+
Some operations can only run on the client—for example:
25+
26+
- Reading the current selection in a canvas or document.
27+
- Inspecting local application state that never leaves the browser.
28+
- Calling into the host app (for example, a design tool or IDE) via its own APIs.
29+
30+
Client tools let the model request that kind of data mid-turn:
31+
32+
- On the server, you instruct your inference pipeline to stop when a specific tool is called (for example, by using `StopAtTools` around that tool).
33+
- ChatKit turns the tool call into a streamed thread item.
34+
- On the client, `onClientTool` receives that item, runs your callback, and returns a JSON result.
35+
- ChatKit sends the result back to the server, which starts a new stream to continue the run with the tool output included as model input.
36+
37+
Use client tools when the model needs fresh, local context it cannot safely obtain from server-side state alone.

docs/concepts/widgets.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ Every widget must be wrapped in a root-level container element. For single, self
3131

3232
## .widget files
3333

34-
Exported `.widget` files are JSON blobs that include the widget template, the expected data schema, and supporting metadata. You can load them server-side and render widgets dynamically with `WidgetTemplate`; see [Build widgets with `WidgetTemplate`](../guides/add-features/stream-widgets.md#build-widgets-with-widgettemplate) for examples.
34+
Exported `.widget` files are JSON blobs that include the widget template, the expected data schema, and supporting metadata. You can load them server-side and render widgets dynamically with `WidgetTemplate`; see [Build widgets with `WidgetTemplate`](../guides/build-interactive-responses-with-widgets.md#build-widgets-with-widgettemplate) for examples.
3535

3636
## WidgetItem
3737

38-
[`WidgetItem`](../../api/chatkit/types/#chatkit.types.WidgetItem) represents a widget rendered as a [thread item](thread-items.md) in the chat UI. In addition to a reference to the widget instance, it contains a `copy_text` field that represents the text value copied to the clipboard when the user clicks the copy button below the response.
38+
[`WidgetItem`](../../api/chatkit/types/#chatkit.types.WidgetItem) represents a widget rendered as a [thread item](threads.md#what-are-thread-items) in the chat UI. In addition to a reference to the widget instance, it contains a `copy_text` field that represents the text value copied to the clipboard when the user clicks the copy button below the response.
3939

4040
## Entity previews
4141

@@ -51,6 +51,4 @@ The [`entities.onRequestPreview`](https://openai.github.io/chatkit-js/api/openai
5151

5252
## Related guides
5353

54-
- [Stream widgets](../guides/add-features/stream-widgets.md)
55-
- [Create custom forms](../guides/add-features/create-custom-forms.md)
56-
- [Handle widget actions](../guides/add-features/handle-widget-actions.md)
54+
- [Build interactive responses with widgets](../guides/build-interactive-responses-with-widgets.md)

0 commit comments

Comments
 (0)