-
Notifications
You must be signed in to change notification settings - Fork 0
feat(broker): support AgentKit tool continuations #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
54b57e2
feat(broker): support AgentKit tool continuations
sozercan 3a3d39c
test(broker): validate hosted streaming cancellation
sozercan 0a7223e
test(broker): cover native AgentKit hosted cancellation
sozercan 2d997ee
fix: add safe broker response diagnostics
sozercan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package broker | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "strings" | ||
| "unicode" | ||
| "unicode/utf8" | ||
|
|
||
| "github.com/orka-agents/agent-runtime-foundry/internal/foundry" | ||
| "github.com/orka-agents/agent-runtime-foundry/internal/strictjson" | ||
| ) | ||
|
|
||
| const ( | ||
| brokerAgentKitProofEnv = "ORKA_FOUNDRY_BROKER_AGENTKIT_CONTINUATION_PROOF" | ||
| brokerAgentKitProofHeader = "X-AgentKit-Brokered-Continuation-Proof" | ||
| ) | ||
|
|
||
| func brokerAgentKitProofValid(value string) bool { | ||
| return value == "" || (len(value) >= 32 && utf8.ValidString(value) && foundry.SafeString(value, 16<<10) && strings.IndexFunc(value, unicode.IsSpace) < 0) | ||
| } | ||
|
|
||
| // The proof never enters the shared request type used by the ACP child. This | ||
| // wire-only extension is added after the broker's owner, lease and call checks. | ||
| func (b *lifecycleBroker) marshalResponseRequest(request foundry.ResponseRequest) ([]byte, error) { | ||
| proof := "" | ||
| if inputs, ok := request.Input.([]any); ok && len(inputs) != 0 { | ||
| proof = b.cfg.agentKitProof | ||
| } | ||
| return json.Marshal(struct { | ||
| foundry.ResponseRequest | ||
| ContinuationProof string `json:"brokered_continuation_proof,omitempty"` | ||
| }{ResponseRequest: request, ContinuationProof: proof}) | ||
| } | ||
|
|
||
| // Orka's MCP proxy explicitly reports isError, with text content and optional | ||
| // structured output. Reject other envelopes rather than infer authorization | ||
| // from arbitrary tool data. JSON-RPC authorization failures never reach here. | ||
| func brokerAgentKitOutputs(request *foundry.ResponseRequest) error { | ||
| if _, first := request.Input.(string); first { | ||
| return nil | ||
| } | ||
| inputs, ok := request.Input.([]any) | ||
| if !ok || len(inputs) == 0 { | ||
| return errBrokerInvalid | ||
| } | ||
| for _, input := range inputs { | ||
| item, ok := input.(map[string]any) | ||
| if !ok { | ||
| return errBrokerInvalid | ||
| } | ||
| output, ok := item["output"].(string) | ||
| if !ok { | ||
| return errBrokerInvalid | ||
| } | ||
| var result struct { | ||
| Content []struct { | ||
| Type string `json:"type"` | ||
| Text *string `json:"text"` | ||
| } `json:"content"` | ||
| IsError *bool `json:"isError"` | ||
| StructuredContent json.RawMessage `json:"structuredContent,omitempty"` | ||
| } | ||
| if strictjson.DecodeStruct([]byte(output), &result, true) != nil || result.Content == nil || result.IsError == nil { | ||
| return errBrokerInvalid | ||
| } | ||
| var message strings.Builder | ||
| for i, content := range result.Content { | ||
| if content.Type != "text" || content.Text == nil { | ||
| return errBrokerInvalid | ||
| } | ||
| if i != 0 { | ||
| message.WriteByte('\n') | ||
| } | ||
| message.WriteString(*content.Text) | ||
| } | ||
| if len(result.StructuredContent) != 0 && result.StructuredContent[0] != '{' { | ||
| return errBrokerInvalid | ||
| } | ||
| var normalized any | ||
| if *result.IsError { | ||
| if message.Len() == 0 { | ||
| message.WriteString("The governed tool returned an error.") | ||
| } | ||
| normalized = map[string]any{"approved": false, "error": map[string]string{ | ||
| "code": "brokered_tool_error", "message": message.String(), | ||
| }} | ||
| } else { | ||
| normalized = map[string]any{"approved": true, "output": result} | ||
| } | ||
| encoded, err := json.Marshal(normalized) | ||
| if err != nil || len(encoded) > foundry.DefaultMaxBrokeredBytes { | ||
| return errBrokerInvalid | ||
| } | ||
| item["output"] = string(encoded) | ||
| } | ||
| return nil | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.