Skip to content

Commit f120b14

Browse files
pontemontiJohan Broberg
andauthored
feat: add Chat History API documentation and recommended usage for Claude SDK (#165)
Co-authored-by: Johan Broberg <johanb@microsoft.com>
1 parent aeaa07f commit f120b14

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

  • packages/agents-a365-tooling-extensions-claude/docs

‎packages/agents-a365-tooling-extensions-claude/docs/design.md‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,80 @@ private readonly orchestratorName: string = "Claude";
201201
// Results in User-Agent header:
202202
// "Agent365SDK/1.0.0 (Windows_NT; Node.js v18.0.0; Claude)"
203203
```
204+
205+
## Chat History API
206+
207+
> **Last Assessed:** January 2026
208+
> **Claude SDK Version:** ^0.1.30 (workspace), `unstable_v2` APIs added in v0.1.54
209+
> **Tracking Issue:** [#164 - Claude SDK: Monitor for chat history API availability](https://github.com/microsoft/Agent365-nodejs/issues/164)
210+
211+
### Current State
212+
213+
Unlike the OpenAI extension which provides `sendChatHistoryAsync` via `OpenAIConversationsSession.getItems()`, the Claude Agent SDK (`@anthropic-ai/claude-agent-sdk`) **does not expose programmatic access to conversation history**.
214+
215+
The SDK includes experimental `unstable_v2_*` session APIs (added in v0.1.54):
216+
- `unstable_v2_createSession` - Creates a new session for multi-turn conversations
217+
- `unstable_v2_resumeSession` - Resumes an existing session by ID
218+
- `unstable_v2_prompt` - One-shot convenience function for single-turn queries
219+
220+
However, these APIs only provide:
221+
- `session.send(message)` - Send a message to Claude
222+
- `session.stream()` - Stream back response messages
223+
- `session.close()` - Close the session
224+
225+
**There is no `session.getHistory()` or equivalent method** to retrieve past messages from a session. Sessions maintain context internally for Claude to reference, but this history is opaque to SDK consumers.
226+
227+
### Recommended Approach
228+
229+
Developers should use the generic `sendChatHistory` method from `@microsoft/agents-a365-tooling` by manually constructing `ChatHistoryMessage[]`:
230+
231+
```typescript
232+
import { McpToolServerConfigurationService, ChatHistoryMessage } from '@microsoft/agents-a365-tooling';
233+
import { TurnContext } from '@microsoft/agents-hosting';
234+
235+
// Build chat history from your conversation tracking
236+
const chatHistory: ChatHistoryMessage[] = [
237+
{
238+
id: 'msg-001',
239+
role: 'user',
240+
content: 'Can you help me find my recent emails?',
241+
timestamp: new Date('2026-01-27T10:00:00Z')
242+
},
243+
{
244+
id: 'msg-002',
245+
role: 'assistant',
246+
content: 'I\'d be happy to help you find your recent emails. Let me search for them now.',
247+
timestamp: new Date('2026-01-27T10:00:05Z')
248+
},
249+
{
250+
id: 'msg-003',
251+
role: 'user',
252+
content: 'Great, show me emails from the last week.',
253+
timestamp: new Date('2026-01-27T10:00:30Z')
254+
}
255+
];
256+
257+
// Send to MCP platform for real-time threat protection
258+
const configService = new McpToolServerConfigurationService();
259+
const result = await configService.sendChatHistory(turnContext, chatHistory);
260+
261+
if (!result.success) {
262+
console.error('Failed to send chat history:', result.error);
263+
}
264+
```
265+
266+
### Revisit Criteria
267+
268+
This limitation should be re-evaluated when any of the following occur:
269+
270+
1. **Claude SDK adds history retrieval API** - Monitor for `session.getHistory()`, `session.getMessages()`, or similar methods
271+
2. **`unstable_v2` APIs stabilize** - When APIs lose the `unstable_` prefix, review for new capabilities
272+
3. **SDK version upgrade** - When upgrading `@anthropic-ai/claude-agent-sdk`, check changelog for history-related features
273+
4. **Anthropic documentation updates** - Monitor [TypeScript V2 Preview docs](https://platform.claude.com/docs/en/agent-sdk/typescript-v2-preview) and [GitHub repo](https://github.com/anthropics/claude-agent-sdk-typescript)
274+
275+
### References
276+
277+
- [Claude Agent SDK - TypeScript V2 Preview](https://platform.claude.com/docs/en/agent-sdk/typescript-v2-preview)
278+
- [Claude Agent SDK - GitHub Repository](https://github.com/anthropics/claude-agent-sdk-typescript)
279+
- [Claude Agent SDK - npm Package](https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk)
280+
- [OpenAI Extension sendChatHistory PR #157](https://github.com/microsoft/Agent365-nodejs/pull/157)

0 commit comments

Comments
 (0)