feat(agent): add AI Agent conversation APIs#109
Draft
sunli829 wants to merge 2 commits into
Draft
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
New
agentpackage (AgentContext) covering the AI Agent conversation API added in longbridge/openapi#557 (docs: longbridge/developers#1129):Workspaces—GET /v1/ai/workspacesAgents—GET /v1/ai/workspaces/{id}/agentsConversation/Continue— blockingPOST .../conversationsand.../continueConversationStream/ContinueStream— same endpoints withAccept: text/event-stream, returning a*ConversationStreamiterator (Next/Event/Err/Close, bufio.Scanner-style)ConversationStreamEventis modeled as an interface with 7 concrete event types (ChatStartedEvent,WorkflowStartedEvent,MessageEvent,PingEvent,ChatFinishedEvent,WorkflowFinishedEvent,ChatTitleUpdatedEvent) plus anOtherEventfallback 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_idaccepts either a JSON string or a raw number across all the payloads that carry it, matching the Rust SDK's defensive deserializationhttp.Clientchanges needed to support this:buildRequest(shared request building/signing) out ofCallCallSSE, returning the raw response body for streaming instead of buffering itWithRequestTimeoutrequest option.AgentContextuses its own underlying*http.Clientwith no overall timeout (a full LLM turn can run long), and instead applies a dedicated 120s timeout to the blockingConversation/Continuecalls only —ConversationStream/ContinueStreamare left unbounded (onlyctxcancellation stops them), matching the Rust core'sAGENT_REQUEST_TIMEOUT/ unbounded-stream-reads design. PlainWorkspaces/AgentsGETs 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-orderchat_title_updated-after-workflow_finishedcase and the docs' succeeded/interruptedConversationResponseexampleshttp/client_test.go—httptest.Server-backed tests forCallSSE(success + error body) andWithRequestTimeoutWorkspaces→Agents→ blockingConversation→ConversationStream, confirming actual SSE event ordering (chat_started→workflow_started→ping→messagechunks →chat_finished→ping→workflow_finished) matches what's implemented