Repository navigation
AI-3464: hosted tool calls in group channels name the writer #2170
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
Open
kanat
wants to merge
6
commits into
main
Choose a base branch
from
ai-3464-hosted-tool-writer
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c97ce18
AI-3464: a tool call in a written turn names its writer
kanat dc339f9
AI-3464: test hosted calls in chat_channels name each turn's writer
kanat 810edb5
AI-3464: say why a writer's turn names its writer
kanat c5891dc
AI-3464: pin the writer on every tool round of a written turn
kanat d039735
AI-3464: clear the last writer wherever a heard or new turn sets the …
kanat 4c7e809
Merge remote-tracking branch 'origin/main' into ai-3464-hosted-tool-w…
kanat 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
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,90 @@ | ||
| //go:build integration | ||
|
|
||
| package api | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/gorilla/websocket" | ||
|
|
||
| "github.com/GetStream/Vision-Agents/acceleration/internal/dispatch" | ||
| "github.com/GetStream/Vision-Agents/acceleration/internal/store" | ||
| ) | ||
|
|
||
| // AI-3464: in a channel of a type a config answers in, a call of a tool the app's backend hosts | ||
| // (a dispatch worker) names the person who wrote the message its turn answers, as a session | ||
| // opened with that person's token does, so the backend can act for them: Anya's turn names Anya, | ||
| // and Ben's next one Ben. | ||
|
|
||
| func (s *AppHooksSuite) TestAHostedCallInAChannelTypeAnsweringMentionsIsForEachTurnsWriter() { | ||
| s.hostedCallsAreForEachWriter(store.ChatChannelAnswerMentioned) | ||
| } | ||
|
|
||
| func (s *AppHooksSuite) TestAHostedCallInAChannelTypeAnsweringEveryMessageIsForEachTurnsWriter() { | ||
| s.hostedCallsAreForEachWriter(store.ChatChannelAnswerAlways) | ||
| } | ||
|
|
||
| // hostedCallsAreForEachWriter has Anya, then Ben, ask a config answering in callouts as answer | ||
| // says, on the model that reaches for lookup_order, which the backend's worker hosts for it and | ||
| // a tool group of the config names. | ||
| func (s *AppHooksSuite) hostedCallsAreForEachWriter(answer string) { | ||
| s.holdsType("callouts", memberWrites) | ||
| config := store.AgentConfig{CustomerID: s.customerID(), Name: "rota-" + s.utils.uuid(), Mode: store.AgentModeText, | ||
| LLM: "tooling/tool-model", ChatChannels: []store.ChatChannel{{Type: "callouts", Answer: answer}}, | ||
| ToolGroups: []store.ToolGroup{{Name: "orders", Tools: []string{lookupOrder}}}} | ||
| s.Require().NoError(s.store.CreateAgentConfig(context.Background(), &config)) | ||
| worker := s.hostsLookupOrder(config.ID) | ||
| mention := "" | ||
| if answer == store.ChatChannelAnswerMentioned { | ||
| mention = fmt.Sprintf(`[{"id": %q, "name": %q}]`, config.ID, config.Name) | ||
| } | ||
| anya, ben := s.person("Anya"), s.person("Ben") | ||
| channel := s.teamChannel("callouts", anya, ben) | ||
| cid := "callouts:" + channel | ||
|
|
||
| s.says("callouts", channel, anya, "where is my order 12?", mention) | ||
| s.Equal(map[string]any{"id": anya, "name": "Anya"}, s.hostedCallUser(worker), "Anya's turn") | ||
| s.Require().Eventually(func() bool { return s.replies(cid) == 1 }, settleFor, 20*time.Millisecond) | ||
|
|
||
| s.says("callouts", channel, ben, "and where is mine?", mention) | ||
| s.Equal(map[string]any{"id": ben, "name": "Ben"}, s.hostedCallUser(worker), "Ben's turn after Anya's") | ||
| s.Require().Eventually(func() bool { return s.replies(cid) == 2 }, settleFor, 20*time.Millisecond) | ||
| } | ||
|
|
||
| // hostsLookupOrder connects a worker of the app's backend hosting lookup_order for the agent id given. | ||
| func (s *RouterSuite) hostsLookupOrder(agentID string) *websocket.Conn { | ||
| worker := s.serverClient.opens("/v1/dispatch") | ||
| s.await(worker, "ready") | ||
| s.Require().NoError(s.dispatch.Host(s.dispatch.Workers(s.customerID())[0], agentID, | ||
| []dispatch.Tool{{Name: lookupOrder, Description: "find an order by its number"}}, time.Minute)) | ||
| return worker | ||
| } | ||
|
|
||
| // hostedCallUser is the user the next call the worker is handed names, nil when it names none, | ||
| // once the worker has answered it. | ||
| func (s *RouterSuite) hostedCallUser(worker *websocket.Conn) any { | ||
| call := s.await(worker, "tool_call") | ||
| s.Require().Equal(lookupOrder, call["name"]) | ||
| s.Require().NoError(worker.WriteJSON(map[string]any{"type": "tool_result", "id": call["id"], "output": "it ships tomorrow"})) | ||
| return call["user"] | ||
| } | ||
|
|
||
| // The control: a session a person opened with their own token names them on a hosted call, as | ||
| // on base b466fb795 (probe of this test there). | ||
| func (s *SessionToolsSuite) TestAHostedCallInASessionOpenedWithAUsersTokenIsForThem() { | ||
| agent := "agent-" + s.utils.uuid() | ||
| worker := s.hostsLookupOrder(agent) | ||
| device := s.data.createUser() | ||
| request := textSession(nil) | ||
| request.AgentId, request.Llm = &agent, pointerTo("tooling/tool-model") | ||
| opened := device.createSession(request) | ||
|
|
||
| status, body := s.serverClient.actingFor(device).call(http.MethodPost, | ||
| "/v1/agents/sessions/"+opened.Id+"/respond", RespondRequest{Text: "where is my order", RequestId: pointerTo("request-" + s.utils.uuid())}) | ||
| s.Require().Equal(http.StatusOK, status, string(body)) | ||
|
|
||
| s.Equal(map[string]any{"id": device.userID}, s.hostedCallUser(worker)) | ||
| } |
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.