Skip to content

feat(agent): add AI Agent conversation APIs#109

Draft
sunli829 wants to merge 2 commits into
mainfrom
feat/agent-conversation-api
Draft

feat(agent): add AI Agent conversation APIs#109
sunli829 wants to merge 2 commits into
mainfrom
feat/agent-conversation-api

Conversation

@sunli829

Copy link
Copy Markdown
Contributor

Summary

  • New agent package (AgentContext) covering the AI Agent conversation API added in longbridge/openapi#557 (docs: longbridge/developers#1129):

    • WorkspacesGET /v1/ai/workspaces
    • AgentsGET /v1/ai/workspaces/{id}/agents
    • Conversation / Continue — blocking POST .../conversations and .../continue
    • ConversationStream / ContinueStream — same endpoints with Accept: text/event-stream, returning a *ConversationStream iterator (Next/Event/Err/Close, bufio.Scanner-style)
    • ConversationStreamEvent is modeled as an interface with 7 concrete event types (ChatStartedEvent, WorkflowStartedEvent, MessageEvent, PingEvent, ChatFinishedEvent, WorkflowFinishedEvent, ChatTitleUpdatedEvent) plus an OtherEvent fallback for forward compatibility — mirrors the Rust core's enum and the four event types the docs don't mention but the Rust PR captured from live traffic (workflow_started, ping, chat_finished, chat_title_updated)
    • message_id accepts either a JSON string or a raw number across all the payloads that carry it, matching the Rust SDK's defensive deserialization
  • http.Client changes needed to support this:

    • Extracted buildRequest (shared request building/signing) out of Call
    • New CallSSE, returning the raw response body for streaming instead of buffering it
    • New WithRequestTimeout request option. AgentContext uses its own underlying *http.Client with no overall timeout (a full LLM turn can run long), and instead applies a dedicated 120s timeout to the blocking Conversation/Continue calls only — ConversationStream/ContinueStream are left unbounded (only ctx cancellation stops them), matching the Rust core's AGENT_REQUEST_TIMEOUT / unbounded-stream-reads design. Plain Workspaces/Agents GETs get a short (15s) timeout via the same option, since they're ordinary fast REST calls.

Test plan

  • go build ./...
  • go vet ./agent/... ./http/...
  • agent/stream_test.go / agent/types_test.go — unit tests replaying the exact SSE fixtures and JSON payloads from the Rust PR's test suite, including the out-of-order chat_title_updated-after-workflow_finished case and the docs' succeeded/interrupted ConversationResponse examples
  • http/client_test.gohttptest.Server-backed tests for CallSSE (success + error body) and WithRequestTimeout
  • Live-tested against the real production API with a real account/workspace/agent: WorkspacesAgents → blocking ConversationConversationStream, confirming actual SSE event ordering (chat_startedworkflow_startedpingmessage chunks → chat_finishedpingworkflow_finished) matches what's implemented

sunli829 added 2 commits July 21, 2026 10:23
Adds the agent package (Workspaces, Agents, Conversation, Continue) with
both blocking and SSE-streamed variants, porting the feature added to the
Rust/C/C++/Java/Node.js/Python SDKs in longbridge/openapi#557 (docs:
longbridge/developers#1129).

http.Client gains CallSSE for streaming responses and a WithRequestTimeout
request option, since a full LLM turn needs a much longer budget than the
shared client default and a streamed run must not be capped by it at all.
Per longbridge/developers#1177, an interrupted streamed run never emits
workflow_finished — only human_interaction_required followed by
chat_finished. Without a typed event for it, ConversationStream/
ContinueStream callers had no way to reach the Interrupt details other
than parsing OtherEvent's raw JSON themselves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant