Skip to content

Latest commit

 

History

History
115 lines (97 loc) · 5.15 KB

File metadata and controls

115 lines (97 loc) · 5.15 KB

ChatKit Node.js Feature Parity with Python SDK

This document tracks the implementation status of features to achieve parity with the Python ChatKit SDK.

Implementation Status: 9/10 Features Complete ✅

✅ Completed Features

  1. Feature #1: Reuse Agent SDK Message IDs

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:187
    • Description: Reuses message IDs from the Agent SDK for consistency instead of generating new ones
    • Matches Python: agents.py:486-487
  2. Feature #2: Support Multiple Content Parts

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:91, 243, 267
    • Description: Tracks text accumulation separately for each content part using content_index from events
    • Matches Python: agents.py:441, 449, 457
  3. Feature #3: Add Content Part Lifecycle Events

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:216-236
    • Description: Emits content_part.added events when content parts are initialized
    • Matches Python: agents.py:434-444
  4. Feature #4: Add Annotations Support (Citations)

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:11-42, 217-232
    • Description: Converts Agent SDK annotations (file citations, URL citations) to ChatKit format
    • Matches Python: agents.py:224-254
  5. Feature #5: Add Workflow/Reasoning Support

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:107-156, 287-372
    • Description: Emits workflow items for GPT-5 reasoning with streaming thought support
    • Matches Python: agents.py:468-526
    • Configuration: Toggle via showThinking option (default: true)
  6. Feature #9: Use SDK's Final Content

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:384-427
    • Description: Uses Agent SDK's final content from response.output_item.done instead of accumulated text
    • Matches Python: agents.py:527-545
  7. Feature #10: Handle response.output_text.done Events

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:265-285
    • Description: Processes response.output_text.done events to finalize content parts
    • Matches Python: agents.py:453-463
  8. Feature #7: Implement Event Merging (Multi-Agent & Widget Support)

    • Status: ✅ Complete
    • Location: Multiple files (see details below)
    • Priority: High (Widget Support)
    • Description: Merge Agent SDK stream events with custom integration events
    • Required for: Custom widgets, multi-agent workflows, advanced integrations
    • Python reference: agents.py:261-294, 386-414
    • Implementation files:
      • src/agents/merge-streams.ts - Stream merging utility
      • src/agents/widget-helpers.ts - diffWidget, accumulateText
      • src/agents/types.ts - AsyncEventQueue, AgentContext extensions
      • src/agents/context-helpers.ts - createAgentContext factory
      • src/server/widget-stream.ts - Standalone streamWidget function
      • src/agents/stream-converter.ts - Integrated merging logic
  9. Feature #6: Add Tool Call Support

    • Status: ✅ Complete
    • Location: src/agents/stream-converter.ts:99-174, 523-554
    • Description: Handle client-side tool calls from Agent SDK tools
    • Matches Python: agents.py:416-426, 177-193, 81-88
    • Implementation:
      • Added ClientToolCall interface to src/agents/types.ts:10-15
      • Added clientToolCall property to AgentContext interface (src/agents/types.ts:150)
      • Track tool calls via run_item_stream_event in stream-converter
      • Emit ClientToolCallItem at end of stream if context.clientToolCall is set
    • Test tool: advanced-chatkit-server.js:229-251 (add_to_todo_list)

🔄 Remaining Features (Advanced Use Cases)

  1. Feature #8: Add Guardrail Handling
    • Status: ⏸️ Pending
    • Priority: Low (Safety/Moderation)
    • Description: Handle input/output guardrail tripwire events
    • Required for: Content moderation, safety checks
    • Python reference: agents.py:570-580
    • Implementation notes:
      • Track produced_items set of item IDs
      • Catch InputGuardrailTripwireTriggered and OutputGuardrailTripwireTriggered exceptions
      • Emit ThreadItemRemovedEvent for all produced items on tripwire
      • Drain remaining events without processing

Testing Coverage

Current test coverage:

  • ✅ Basic message streaming
  • ✅ Reasoning/workflow display
  • ✅ Annotations/citations
  • ✅ Multiple content parts
  • ✅ Widget streaming (Feature #7)
  • ✅ Custom event merging (Feature #7)
  • ✅ Client tool calls (Feature #6)
  • ⏸️ Guardrail handling (pending Feature #8)

Notes

  • All completed features match Python SDK behavior
  • Configuration options (e.g., showThinking) match Python patterns
  • Event types and structure match ChatKit protocol specification
  • Widget system fully implemented with streaming support
  • Client tool call support fully implemented
  • Ready for production use with single-agent and multi-agent workflows
  • Tools can emit custom widgets using context.streamWidget()
  • Tools can trigger client-side actions using context.clientToolCall
  • Supports both static widgets and streaming widget generators