bots-garden/sidekickspublic Fork
⑂ cc9e2a7
Commits
⬇ Clone ▾
git clone https://git.rickub.com/bots-garden/sidekicks.git
git clone ssh://git@rickub.com/bots-garden/sidekicks.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Download ZIP

#26 Message à plusieurs agents : chacun apprend son nom, l'ordre et sa part du message

« @alice écris une histoire, puis @bob résume-la » : Alice recevait le texte
brut sans savoir qu'elle est @alice, et Bob faisait tout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
k33g committed 2026-11-10T05:06:59+01:00 Browse files
cc9e2a7 parent: cf64214
modified .memory/history.md +1 -0
@@ -219,3 +219,4 @@
219219 - Also filed #75–#80 (collective memory REST API, MCP mode question, MCP gateway, plugins, acting outside, prompt injection), no milestone.
220220 - **2026-11-09 — #51 unload a model from the Log panel** (owner: "/unload already works; from the Log panel, unload the selected model or all of them"): convention kept — an agent that announces the `unload` slash command can unload its model. `channels.Manager.Unload` sends `/unload` in a throwaway session (no trace in conversations; refuses no-command / answering agents), `AgentService.Unload` also refuses a stopped agent and writes the answer to the agent log (`unload: …`), `UnloadAll` returns `{unloaded, skipped}` without starting stopped agents. UI: ⏏ Unload the model + ⏏ Unload all in the Log panel (result line), ⏏ on the agent row and in the agent view header; the frontend decides visibility from `appState.commands` (no `canUnload` in `List()`, it would be lost on agent:state events). Verified under Xvfb with two fake ACP agents (Python, scratchpad). Docs EN/FR: memory-pressure how-to, memory explanation, AgentService reference.
221221 - **2026-11-09 — #26 agents calling agents** (owner: "add #26 to the milestone and implement it"): chose @mentions in answers over an MCP "ask_agent" tool (mm ignores mcpServers). In a channel, members mentioned in an agent's answer answer next (`channels.Manager.answer` loop; `HandoffPrompt` tells them who addressed them; unseen includes the user's message). Guards: members only, not self, not already queued, not in code, not after a /command, not in direct conversations; `limits.maxAgentHandoffs` (default 3, 0–10, 0 = off; `*int` in raw config, read per message via `Options.Handoffs` → `Core.maxAgentHandoffs`), then system message `handoff-limit`; ■ stops the chain. Verified under Xvfb with two fake agents mentioning each other. Docs EN/FR: manage-channels how-to, channels-and-context explanation, configuration + agents-and-events references.
222+- **2026-11-10 — messages for several agents** (owner tested "@alice make a story about seven of nine, then @bob make a summary of this story": Alice asked for the story, Bob did everything; "@alice … ensuite demande à @bob d'en faire un résumé" worked): cause — with nothing unseen, Alice got the raw text and does not know she is @alice. Now, when a user message routes to several agents in a channel, `SharedPrompt` tells each one its name, the answer order and its part (`PartFor`: words after its first mention up to the next addressed agent's mention, code masked; none under two words = request for all). The fake conn matches scripts on the user's text inside a shared prompt. Docs EN/FR: manage-channels row, channels-and-context explanation, agents-and-events routing row. Not yet tried with mm.
@@ -219,3 +219,4 @@
219 - Also filed #75–#80 (collective memory REST API, MCP mode question, MCP gateway, plugins, acting outside, prompt injection), no milestone.219 - Also filed #75–#80 (collective memory REST API, MCP mode question, MCP gateway, plugins, acting outside, prompt injection), no milestone.
220 - **2026-11-09 — #51 unload a model from the Log panel** (owner: "/unload already works; from the Log panel, unload the selected model or all of them"): convention kept — an agent that announces the `unload` slash command can unload its model. `channels.Manager.Unload` sends `/unload` in a throwaway session (no trace in conversations; refuses no-command / answering agents), `AgentService.Unload` also refuses a stopped agent and writes the answer to the agent log (`unload: …`), `UnloadAll` returns `{unloaded, skipped}` without starting stopped agents. UI: ⏏ Unload the model + ⏏ Unload all in the Log panel (result line), ⏏ on the agent row and in the agent view header; the frontend decides visibility from `appState.commands` (no `canUnload` in `List()`, it would be lost on agent:state events). Verified under Xvfb with two fake ACP agents (Python, scratchpad). Docs EN/FR: memory-pressure how-to, memory explanation, AgentService reference.220 - **2026-11-09 — #51 unload a model from the Log panel** (owner: "/unload already works; from the Log panel, unload the selected model or all of them"): convention kept — an agent that announces the `unload` slash command can unload its model. `channels.Manager.Unload` sends `/unload` in a throwaway session (no trace in conversations; refuses no-command / answering agents), `AgentService.Unload` also refuses a stopped agent and writes the answer to the agent log (`unload: …`), `UnloadAll` returns `{unloaded, skipped}` without starting stopped agents. UI: ⏏ Unload the model + ⏏ Unload all in the Log panel (result line), ⏏ on the agent row and in the agent view header; the frontend decides visibility from `appState.commands` (no `canUnload` in `List()`, it would be lost on agent:state events). Verified under Xvfb with two fake ACP agents (Python, scratchpad). Docs EN/FR: memory-pressure how-to, memory explanation, AgentService reference.
221 - **2026-11-09 — #26 agents calling agents** (owner: "add #26 to the milestone and implement it"): chose @mentions in answers over an MCP "ask_agent" tool (mm ignores mcpServers). In a channel, members mentioned in an agent's answer answer next (`channels.Manager.answer` loop; `HandoffPrompt` tells them who addressed them; unseen includes the user's message). Guards: members only, not self, not already queued, not in code, not after a /command, not in direct conversations; `limits.maxAgentHandoffs` (default 3, 0–10, 0 = off; `*int` in raw config, read per message via `Options.Handoffs` → `Core.maxAgentHandoffs`), then system message `handoff-limit`; ■ stops the chain. Verified under Xvfb with two fake agents mentioning each other. Docs EN/FR: manage-channels how-to, channels-and-context explanation, configuration + agents-and-events references.221 - **2026-11-09 — #26 agents calling agents** (owner: "add #26 to the milestone and implement it"): chose @mentions in answers over an MCP "ask_agent" tool (mm ignores mcpServers). In a channel, members mentioned in an agent's answer answer next (`channels.Manager.answer` loop; `HandoffPrompt` tells them who addressed them; unseen includes the user's message). Guards: members only, not self, not already queued, not in code, not after a /command, not in direct conversations; `limits.maxAgentHandoffs` (default 3, 0–10, 0 = off; `*int` in raw config, read per message via `Options.Handoffs` → `Core.maxAgentHandoffs`), then system message `handoff-limit`; ■ stops the chain. Verified under Xvfb with two fake agents mentioning each other. Docs EN/FR: manage-channels how-to, channels-and-context explanation, configuration + agents-and-events references.
222+- **2026-11-10 — messages for several agents** (owner tested "@alice make a story about seven of nine, then @bob make a summary of this story": Alice asked for the story, Bob did everything; "@alice … ensuite demande à @bob d'en faire un résumé" worked): cause — with nothing unseen, Alice got the raw text and does not know she is @alice. Now, when a user message routes to several agents in a channel, `SharedPrompt` tells each one its name, the answer order and its part (`PartFor`: words after its first mention up to the next addressed agent's mention, code masked; none under two words = request for all). The fake conn matches scripts on the user's text inside a shared prompt. Docs EN/FR: manage-channels row, channels-and-context explanation, agents-and-events routing row. Not yet tried with mm.
modified docs/en/explanation/channels-and-context.md +1 -1
@@ -16,7 +16,7 @@ The alternative, one shared session that every agent reads, does not exist in AC
1616
1717 A message goes to the agents it mentions, in order; without a mention, to the last agent who spoke. That is how people talk in a group: you name someone, or you carry on with the person you were talking to. Nobody answers a message that names nobody in a channel where several agents have not spoken yet — guessing would surprise the user more than asking them to choose.
1818
19-Agents answer one after the other, never at the same time. On a laptop, two local models generating together are each slower than one after the other, and memory is the real limit (two small models on the reference machine). Answering in turn also lets the second agent read the first one's answer: "@alice @bob compare" gives Bob Alice's answer to compare with. For the same reason an agent answers one channel at a time: a second channel waits, and shows whose turn it is.
19+Agents answer one after the other, never at the same time. On a laptop, two local models generating together are each slower than one after the other, and memory is the real limit (two small models on the reference machine). Answering in turn also lets the second agent read the first one's answer: "@alice @bob compare" gives Bob Alice's answer to compare with. A small model does not know its own name, though: given "@alice write a story, then @bob sum it up", Alice may wait for a story, and Bob may write it and sum it up. So when a message addresses several agents, each one is told who it is, in which order they answer, and its part — the words after its name, up to the next agent's name. A part shorter than two words ("@alice and @bob, tell a joke") means the request is for everyone. For the same reason an agent answers one channel at a time: a second channel waits, and shows whose turn it is.
2020
2121 ## When an agent calls another one
2222
@@ -16,7 +16,7 @@ The alternative, one shared session that every agent reads, does not exist in AC
16 16
17 A message goes to the agents it mentions, in order; without a mention, to the last agent who spoke. That is how people talk in a group: you name someone, or you carry on with the person you were talking to. Nobody answers a message that names nobody in a channel where several agents have not spoken yet — guessing would surprise the user more than asking them to choose.17 A message goes to the agents it mentions, in order; without a mention, to the last agent who spoke. That is how people talk in a group: you name someone, or you carry on with the person you were talking to. Nobody answers a message that names nobody in a channel where several agents have not spoken yet — guessing would surprise the user more than asking them to choose.
18 18
19-Agents answer one after the other, never at the same time. On a laptop, two local models generating together are each slower than one after the other, and memory is the real limit (two small models on the reference machine). Answering in turn also lets the second agent read the first one's answer: "@alice @bob compare" gives Bob Alice's answer to compare with. For the same reason an agent answers one channel at a time: a second channel waits, and shows whose turn it is.19+Agents answer one after the other, never at the same time. On a laptop, two local models generating together are each slower than one after the other, and memory is the real limit (two small models on the reference machine). Answering in turn also lets the second agent read the first one's answer: "@alice @bob compare" gives Bob Alice's answer to compare with. A small model does not know its own name, though: given "@alice write a story, then @bob sum it up", Alice may wait for a story, and Bob may write it and sum it up. So when a message addresses several agents, each one is told who it is, in which order they answer, and its part — the words after its name, up to the next agent's name. A part shorter than two words ("@alice and @bob, tell a joke") means the request is for everyone. For the same reason an agent answers one channel at a time: a second channel waits, and shows whose turn it is.
20 20
21 ## When an agent calls another one21 ## When an agent calls another one
22 22
modified docs/en/how-to/manage-channels.md +1 -0
@@ -44,6 +44,7 @@ While an agent is answering, the history cannot be cleared: stop it (**■**) or
4444 | --- | --- |
4545 | a specific agent to answer | `@name your message` (the list after `@` filters as you type; Tab or Enter picks) |
4646 | several agents to answer in turn | `@alice @bob compare your answers` |
47+| each agent to do its own part | `@alice write a story about Picard, then @bob sum it up`: each agent is told the words after its name |
4748 | an agent to involve another one | ask it: `@alice …, and ask @bob` ([below](#let-the-agents-call-each-other)) |
4849 | the agent you were talking with | your message, without mention |
4950 | an agent's command | `/` then pick it in the list; with several agents, `/agent:command` |
@@ -44,6 +44,7 @@ While an agent is answering, the history cannot be cleared: stop it (**■**) or
44 | --- | --- |44 | --- | --- |
45 | a specific agent to answer | `@name your message` (the list after `@` filters as you type; Tab or Enter picks) |45 | a specific agent to answer | `@name your message` (the list after `@` filters as you type; Tab or Enter picks) |
46 | several agents to answer in turn | `@alice @bob compare your answers` |46 | several agents to answer in turn | `@alice @bob compare your answers` |
47+| each agent to do its own part | `@alice write a story about Picard, then @bob sum it up`: each agent is told the words after its name |
47 | an agent to involve another one | ask it: `@alice …, and ask @bob` ([below](#let-the-agents-call-each-other)) |48 | an agent to involve another one | ask it: `@alice …, and ask @bob` ([below](#let-the-agents-call-each-other)) |
48 | the agent you were talking with | your message, without mention |49 | the agent you were talking with | your message, without mention |
49 | an agent's command | `/` then pick it in the list; with several agents, `/agent:command` |50 | an agent's command | `/` then pick it in the list; with several agents, `/agent:command` |
modified docs/en/reference/agents-and-events.md +1 -1
@@ -73,7 +73,7 @@ A channel holds a conversation between the user and one or several agents. A dir
7373 | The message | Answered by |
7474 | --- | --- |
7575 | `/agent:command arguments` (`agent` is a configured agent) | that agent, which receives `/command arguments` |
76-| contains `@name` mentions of configured agents | the mentioned agents, one after the other, in the order of the mentions; a mentioned agent that is not a member joins first |
76+| contains `@name` mentions of configured agents | the mentioned agents, one after the other, in the order of the mentions; a mentioned agent that is not a member joins first. With several agents, each one is told its name, the order, and its part (the words after its mention, up to the next answering agent's mention; none under two words) |
7777 | no mention | the last agent who answered in the channel; with a single member, that member |
7878 | no mention and nobody answered yet, several members | nobody: system message `no-recipient` |
7979 | any message in a direct conversation | its agent; mentions are plain text there |
@@ -73,7 +73,7 @@ A channel holds a conversation between the user and one or several agents. A dir
73 | The message | Answered by |73 | The message | Answered by |
74 | --- | --- |74 | --- | --- |
75 | `/agent:command arguments` (`agent` is a configured agent) | that agent, which receives `/command arguments` |75 | `/agent:command arguments` (`agent` is a configured agent) | that agent, which receives `/command arguments` |
76-| contains `@name` mentions of configured agents | the mentioned agents, one after the other, in the order of the mentions; a mentioned agent that is not a member joins first |76+| contains `@name` mentions of configured agents | the mentioned agents, one after the other, in the order of the mentions; a mentioned agent that is not a member joins first. With several agents, each one is told its name, the order, and its part (the words after its mention, up to the next answering agent's mention; none under two words) |
77 | no mention | the last agent who answered in the channel; with a single member, that member |77 | no mention | the last agent who answered in the channel; with a single member, that member |
78 | no mention and nobody answered yet, several members | nobody: system message `no-recipient` |78 | no mention and nobody answered yet, several members | nobody: system message `no-recipient` |
79 | any message in a direct conversation | its agent; mentions are plain text there |79 | any message in a direct conversation | its agent; mentions are plain text there |
modified docs/fr/explanation/channels-et-contexte.md +1 -1
@@ -16,7 +16,7 @@ L'alternative, une session commune lue par tous les agents, n'existe pas dans AC
1616
1717 Un message va aux agents qu'il mentionne, dans l'ordre ; sans mention, au dernier agent qui a parlé. C'est ainsi qu'on parle en groupe : on nomme quelqu'un, ou on continue avec la personne à qui l'on parlait. Personne ne répond à un message qui ne nomme personne dans un channel où plusieurs agents n'ont pas encore parlé — deviner surprendrait davantage l'utilisateur que lui demander de choisir.
1818
19-Les agents répondent l'un après l'autre, jamais en même temps. Sur un portable, deux modèles locaux qui génèrent ensemble sont chacun plus lents qu'à tour de rôle, et la mémoire est la vraie limite (deux petits modèles sur la machine de référence). Répondre à tour de rôle permet aussi au second agent de lire la réponse du premier : « @alice @bob comparez » donne à Bob la réponse d'Alice à comparer. Pour la même raison, un agent répond à un seul channel à la fois : un second channel attend, et indique à qui c'est le tour.
19+Les agents répondent l'un après l'autre, jamais en même temps. Sur un portable, deux modèles locaux qui génèrent ensemble sont chacun plus lents qu'à tour de rôle, et la mémoire est la vraie limite (deux petits modèles sur la machine de référence). Répondre à tour de rôle permet aussi au second agent de lire la réponse du premier : « @alice @bob comparez » donne à Bob la réponse d'Alice à comparer. Mais un petit modèle ne connaît pas son propre nom : devant « @alice écris une histoire, puis @bob résume-la », Alice peut attendre qu'on lui donne une histoire, et Bob l'écrire puis la résumer. Quand un message s'adresse à plusieurs agents, chacun apprend donc qui il est, dans quel ordre ils répondent, et sa part : les mots qui suivent son nom, jusqu'au nom de l'agent suivant. Une part de moins de deux mots (« @alice et @bob, une blague ») veut dire que la demande est pour tous. Pour la même raison, un agent répond à un seul channel à la fois : un second channel attend, et indique à qui c'est le tour.
2020
2121 ## Quand un agent en appelle un autre
2222
@@ -16,7 +16,7 @@ L'alternative, une session commune lue par tous les agents, n'existe pas dans AC
16 16
17 Un message va aux agents qu'il mentionne, dans l'ordre ; sans mention, au dernier agent qui a parlé. C'est ainsi qu'on parle en groupe : on nomme quelqu'un, ou on continue avec la personne à qui l'on parlait. Personne ne répond à un message qui ne nomme personne dans un channel où plusieurs agents n'ont pas encore parlé — deviner surprendrait davantage l'utilisateur que lui demander de choisir.17 Un message va aux agents qu'il mentionne, dans l'ordre ; sans mention, au dernier agent qui a parlé. C'est ainsi qu'on parle en groupe : on nomme quelqu'un, ou on continue avec la personne à qui l'on parlait. Personne ne répond à un message qui ne nomme personne dans un channel où plusieurs agents n'ont pas encore parlé — deviner surprendrait davantage l'utilisateur que lui demander de choisir.
18 18
19-Les agents répondent l'un après l'autre, jamais en même temps. Sur un portable, deux modèles locaux qui génèrent ensemble sont chacun plus lents qu'à tour de rôle, et la mémoire est la vraie limite (deux petits modèles sur la machine de référence). Répondre à tour de rôle permet aussi au second agent de lire la réponse du premier : « @alice @bob comparez » donne à Bob la réponse d'Alice à comparer. Pour la même raison, un agent répond à un seul channel à la fois : un second channel attend, et indique à qui c'est le tour.19+Les agents répondent l'un après l'autre, jamais en même temps. Sur un portable, deux modèles locaux qui génèrent ensemble sont chacun plus lents qu'à tour de rôle, et la mémoire est la vraie limite (deux petits modèles sur la machine de référence). Répondre à tour de rôle permet aussi au second agent de lire la réponse du premier : « @alice @bob comparez » donne à Bob la réponse d'Alice à comparer. Mais un petit modèle ne connaît pas son propre nom : devant « @alice écris une histoire, puis @bob résume-la », Alice peut attendre qu'on lui donne une histoire, et Bob l'écrire puis la résumer. Quand un message s'adresse à plusieurs agents, chacun apprend donc qui il est, dans quel ordre ils répondent, et sa part : les mots qui suivent son nom, jusqu'au nom de l'agent suivant. Une part de moins de deux mots (« @alice et @bob, une blague ») veut dire que la demande est pour tous. Pour la même raison, un agent répond à un seul channel à la fois : un second channel attend, et indique à qui c'est le tour.
20 20
21 ## Quand un agent en appelle un autre21 ## Quand un agent en appelle un autre
22 22
modified docs/fr/how-to/gerer-les-channels.md +1 -0
@@ -44,6 +44,7 @@ Pendant qu'un agent répond, l'historique ne peut pas être vidé : arrêtez-le
4444 | --- | --- |
4545 | qu'un agent précis réponde | `@nom votre message` (la liste après `@` se filtre pendant la frappe ; Tab ou Entrée choisit) |
4646 | que plusieurs agents répondent à tour de rôle | `@alice @bob comparez vos réponses` |
47+| que chaque agent fasse sa part | `@alice écris une histoire sur Picard, puis @bob résume-la` : chaque agent reçoit les mots qui suivent son nom |
4748 | qu'un agent en fasse intervenir un autre | demandez-le-lui : `@alice …, et demande à @bob` ([plus bas](#laisser-les-agents-sappeler-entre-eux)) |
4849 | continuer avec l'agent à qui vous parliez | votre message, sans mention |
4950 | une commande d'un agent | `/` puis choisissez-la dans la liste ; avec plusieurs agents, `/agent:commande` |
@@ -44,6 +44,7 @@ Pendant qu'un agent répond, l'historique ne peut pas être vidé : arrêtez-le
44 | --- | --- |44 | --- | --- |
45 | qu'un agent précis réponde | `@nom votre message` (la liste après `@` se filtre pendant la frappe ; Tab ou Entrée choisit) |45 | qu'un agent précis réponde | `@nom votre message` (la liste après `@` se filtre pendant la frappe ; Tab ou Entrée choisit) |
46 | que plusieurs agents répondent à tour de rôle | `@alice @bob comparez vos réponses` |46 | que plusieurs agents répondent à tour de rôle | `@alice @bob comparez vos réponses` |
47+| que chaque agent fasse sa part | `@alice écris une histoire sur Picard, puis @bob résume-la` : chaque agent reçoit les mots qui suivent son nom |
47 | qu'un agent en fasse intervenir un autre | demandez-le-lui : `@alice …, et demande à @bob` ([plus bas](#laisser-les-agents-sappeler-entre-eux)) |48 | qu'un agent en fasse intervenir un autre | demandez-le-lui : `@alice …, et demande à @bob` ([plus bas](#laisser-les-agents-sappeler-entre-eux)) |
48 | continuer avec l'agent à qui vous parliez | votre message, sans mention |49 | continuer avec l'agent à qui vous parliez | votre message, sans mention |
49 | une commande d'un agent | `/` puis choisissez-la dans la liste ; avec plusieurs agents, `/agent:commande` |50 | une commande d'un agent | `/` puis choisissez-la dans la liste ; avec plusieurs agents, `/agent:commande` |
modified docs/fr/reference/agents-et-evenements.md +1 -1
@@ -73,7 +73,7 @@ Un channel contient une conversation entre l'utilisateur et un ou plusieurs agen
7373 | Le message | Répondu par |
7474 | --- | --- |
7575 | `/agent:commande arguments` (`agent` est un agent de la configuration) | cet agent, qui reçoit `/commande arguments` |
76-| contient des mentions `@nom` d'agents de la configuration | les agents mentionnés, l'un après l'autre, dans l'ordre des mentions ; un agent mentionné qui n'est pas membre rejoint d'abord le channel |
76+| contient des mentions `@nom` d'agents de la configuration | les agents mentionnés, l'un après l'autre, dans l'ordre des mentions ; un agent mentionné qui n'est pas membre rejoint d'abord le channel. Avec plusieurs agents, chacun reçoit son nom, l'ordre et sa part (les mots après sa mention, jusqu'à celle de l'agent suivant qui répond ; aucune sous deux mots) |
7777 | sans mention | le dernier agent qui a répondu dans le channel ; avec un seul membre, ce membre |
7878 | sans mention, personne n'a encore répondu, plusieurs membres | personne : message système `no-recipient` |
7979 | tout message d'une conversation directe | son agent ; les mentions y sont du simple texte |
@@ -73,7 +73,7 @@ Un channel contient une conversation entre l'utilisateur et un ou plusieurs agen
73 | Le message | Répondu par |73 | Le message | Répondu par |
74 | --- | --- |74 | --- | --- |
75 | `/agent:commande arguments` (`agent` est un agent de la configuration) | cet agent, qui reçoit `/commande arguments` |75 | `/agent:commande arguments` (`agent` est un agent de la configuration) | cet agent, qui reçoit `/commande arguments` |
76-| contient des mentions `@nom` d'agents de la configuration | les agents mentionnés, l'un après l'autre, dans l'ordre des mentions ; un agent mentionné qui n'est pas membre rejoint d'abord le channel |76+| contient des mentions `@nom` d'agents de la configuration | les agents mentionnés, l'un après l'autre, dans l'ordre des mentions ; un agent mentionné qui n'est pas membre rejoint d'abord le channel. Avec plusieurs agents, chacun reçoit son nom, l'ordre et sa part (les mots après sa mention, jusqu'à celle de l'agent suivant qui répond ; aucune sous deux mots) |
77 | sans mention | le dernier agent qui a répondu dans le channel ; avec un seul membre, ce membre |77 | sans mention | le dernier agent qui a répondu dans le channel ; avec un seul membre, ce membre |
78 | sans mention, personne n'a encore répondu, plusieurs membres | personne : message système `no-recipient` |78 | sans mention, personne n'a encore répondu, plusieurs membres | personne : message système `no-recipient` |
79 | tout message d'une conversation directe | son agent ; les mentions y sont du simple texte |79 | tout message d'une conversation directe | son agent ; les mentions y sont du simple texte |
modified internal/channels/fakes_test.go +5 -0
@@ -84,6 +84,11 @@ func (c *fakeConn) Prompt(ctx context.Context, sessionID string, text string, at
8484 c.attachments = append(c.attachments, attachments)
8585 handler := c.handlers[sessionID]
8686 play := c.scripts[text]
87+ if _, message, shared := strings.Cut(text, "The user's message:\n"); play == nil && shared {
88+ // A message for several agents (SharedPrompt): the script is the user's text.
89+ message, _, _ = strings.Cut(message, "\n\n")
90+ play = c.scripts[message]
91+ }
8792 reply := c.reply
8893 c.mu.Unlock()
8994 if play == nil {
@@ -84,6 +84,11 @@ func (c *fakeConn) Prompt(ctx context.Context, sessionID string, text string, at
84 c.attachments = append(c.attachments, attachments)84 c.attachments = append(c.attachments, attachments)
85 handler := c.handlers[sessionID]85 handler := c.handlers[sessionID]
86 play := c.scripts[text]86 play := c.scripts[text]
87+ if _, message, shared := strings.Cut(text, "The user's message:\n"); play == nil && shared {
88+ // A message for several agents (SharedPrompt): the script is the user's text.
89+ message, _, _ = strings.Cut(message, "\n\n")
90+ play = c.scripts[message]
91+ }
87 reply := c.reply92 reply := c.reply
88 c.mu.Unlock()93 c.mu.Unlock()
89 if play == nil {94 if play == nil {
modified internal/channels/route.go +55 -0
@@ -5,6 +5,7 @@ package channels
55 import (
66 "fmt"
77 "regexp"
8+ "slices"
89 "strings"
910 )
1011
@@ -162,3 +163,57 @@ func HandoffPrompt(agent, from, channelName string, unseen []Line) string {
162163 fmt.Fprintf(&builder, "%s mentioned you (@%s) in its last message in %s: answer %s directly, without your name in front.", from, agent, channelName, from)
163164 return builder.String()
164165 }
166+
167+// SharedPrompt builds what agent receives for a user message that addresses
168+// several agents (addressed, in the order they answer): small models do not
169+// know their own name, and take "@alice write a story, then @bob sum it up"
170+// for a request to both. Each agent is told who it is, who answers before
171+// and after it, and the part of the message that follows its mention (PartFor).
172+//
173+// SharedPrompt("alice", "#general", "@alice write a story, then @bob sum it up", []string{"alice", "bob"}, nil)
174+func SharedPrompt(agent, channelName, text string, addressed []string, unseen []Line) string {
175+ var builder strings.Builder
176+ writeUnseen(&builder, agent, channelName, unseen)
177+ names := make([]string, len(addressed))
178+ for i, name := range addressed {
179+ names[i] = "@" + name
180+ }
181+ fmt.Fprintf(&builder, "The user writes to several agents in %s, who answer one after the other in this order: %s. You are @%s.\n", channelName, strings.Join(names, ", "), agent)
182+ fmt.Fprintf(&builder, "The user's message:\n%s\n\n", text)
183+ if part := PartFor(text, agent, addressed); part != "" {
184+ fmt.Fprintf(&builder, "Your part of it: %s\nDo only your part, the others do theirs. ", part)
185+ }
186+ builder.WriteString("Answer directly, without your name in front.")
187+ return builder.String()
188+}
189+
190+// PartFor returns what the user asks agent in a message that addresses several
191+// agents: the words after agent's first mention, up to the mention of
192+// another addressed agent. "" when there are fewer than two words — the
193+// request is then for everyone ("@alice and @bob, tell a joke"). Code is
194+// not looked into.
195+//
196+// PartFor("@alice write a story, then @bob sum it up", "bob", []string{"alice", "bob"}) // "sum it up"
197+func PartFor(text, agent string, addressed []string) string {
198+ masked := codePattern.ReplaceAllStringFunc(text, func(code string) string { return strings.Repeat(" ", len(code)) })
199+ start, end := -1, len(text)
200+ for _, match := range mentionPattern.FindAllStringSubmatchIndex(masked, -1) {
201+ name := masked[match[4]:match[5]]
202+ if start < 0 && name == agent {
203+ start = match[5]
204+ continue
205+ }
206+ if start >= 0 && name != agent && slices.Contains(addressed, name) {
207+ end = match[4] - 1 // the @
208+ break
209+ }
210+ }
211+ if start < 0 {
212+ return ""
213+ }
214+ part := strings.Trim(text[start:end], " \t\n,;:")
215+ if len(strings.Fields(part)) < 2 {
216+ return ""
217+ }
218+ return part
219+}
@@ -5,6 +5,7 @@ package channels
5 import (5 import (
6 "fmt"6 "fmt"
7 "regexp"7 "regexp"
8+ "slices"
8 "strings"9 "strings"
9 )10 )
10 11
@@ -162,3 +163,57 @@ func HandoffPrompt(agent, from, channelName string, unseen []Line) string {
162 fmt.Fprintf(&builder, "%s mentioned you (@%s) in its last message in %s: answer %s directly, without your name in front.", from, agent, channelName, from)163 fmt.Fprintf(&builder, "%s mentioned you (@%s) in its last message in %s: answer %s directly, without your name in front.", from, agent, channelName, from)
163 return builder.String()164 return builder.String()
164 }165 }
166+
167+// SharedPrompt builds what agent receives for a user message that addresses
168+// several agents (addressed, in the order they answer): small models do not
169+// know their own name, and take "@alice write a story, then @bob sum it up"
170+// for a request to both. Each agent is told who it is, who answers before
171+// and after it, and the part of the message that follows its mention (PartFor).
172+//
173+// SharedPrompt("alice", "#general", "@alice write a story, then @bob sum it up", []string{"alice", "bob"}, nil)
174+func SharedPrompt(agent, channelName, text string, addressed []string, unseen []Line) string {
175+ var builder strings.Builder
176+ writeUnseen(&builder, agent, channelName, unseen)
177+ names := make([]string, len(addressed))
178+ for i, name := range addressed {
179+ names[i] = "@" + name
180+ }
181+ fmt.Fprintf(&builder, "The user writes to several agents in %s, who answer one after the other in this order: %s. You are @%s.\n", channelName, strings.Join(names, ", "), agent)
182+ fmt.Fprintf(&builder, "The user's message:\n%s\n\n", text)
183+ if part := PartFor(text, agent, addressed); part != "" {
184+ fmt.Fprintf(&builder, "Your part of it: %s\nDo only your part, the others do theirs. ", part)
185+ }
186+ builder.WriteString("Answer directly, without your name in front.")
187+ return builder.String()
188+}
189+
190+// PartFor returns what the user asks agent in a message that addresses several
191+// agents: the words after agent's first mention, up to the mention of
192+// another addressed agent. "" when there are fewer than two words — the
193+// request is then for everyone ("@alice and @bob, tell a joke"). Code is
194+// not looked into.
195+//
196+// PartFor("@alice write a story, then @bob sum it up", "bob", []string{"alice", "bob"}) // "sum it up"
197+func PartFor(text, agent string, addressed []string) string {
198+ masked := codePattern.ReplaceAllStringFunc(text, func(code string) string { return strings.Repeat(" ", len(code)) })
199+ start, end := -1, len(text)
200+ for _, match := range mentionPattern.FindAllStringSubmatchIndex(masked, -1) {
201+ name := masked[match[4]:match[5]]
202+ if start < 0 && name == agent {
203+ start = match[5]
204+ continue
205+ }
206+ if start >= 0 && name != agent && slices.Contains(addressed, name) {
207+ end = match[4] - 1 // the @
208+ break
209+ }
210+ }
211+ if start < 0 {
212+ return ""
213+ }
214+ part := strings.Trim(text[start:end], " \t\n,;:")
215+ if len(strings.Fields(part)) < 2 {
216+ return ""
217+ }
218+ return part
219+}
modified internal/channels/route_test.go +46 -0
@@ -111,3 +111,49 @@ func TestReferencesAreTheFilesJoinedWithADollar(t *testing.T) {
111111 }
112112 }
113113 }
114+
115+func TestPartForIsWhatFollowsTheAgentsMention(t *testing.T) {
116+ addressed := []string{"alice", "bob"}
117+ text := "@alice make a story about seven of nine, then @bob make a summary of this story"
118+ cases := map[string]string{"alice": "make a story about seven of nine, then", "bob": "make a summary of this story"}
119+ for agent, want := range cases {
120+ if got := channels.PartFor(text, agent, addressed); got != want {
121+ t.Errorf("%s: got %q, want %q", agent, got, want)
122+ }
123+ }
124+ shared := map[string]string{
125+ "@alice and @bob, tell me a joke": "alice", // one word: the request is for both
126+ "@alice @bob compare": "bob",
127+ "tell me @bob`@alice`": "alice", // a mention in code is text
128+ }
129+ for text, agent := range shared {
130+ if got := channels.PartFor(text, agent, addressed); got != "" {
131+ t.Errorf("%q for %s: got %q, want nothing", text, agent, got)
132+ }
133+ }
134+ if got := channels.PartFor("@alice and @bob, tell me a joke", "bob", addressed); got != "tell me a joke" {
135+ t.Errorf("got %q", got)
136+ }
137+ // Only the agents that answer cut a part: @carol is just text here.
138+ if got := channels.PartFor("@alice ask @carol about trains", "alice", addressed); got != "ask @carol about trains" {
139+ t.Errorf("got %q", got)
140+ }
141+}
142+
143+func TestSharedPromptTellsTheAgentWhoItIsAndItsPart(t *testing.T) {
144+ text := "@alice make a story, then @bob sum it up"
145+ got := channels.SharedPrompt("bob", "#general", text, []string{"alice", "bob"}, []channels.Line{{Author: "alice", Text: "Once upon a time."}})
146+ want := "[Messages in #general you have not seen yet]\n" +
147+ "alice: Once upon a time.\n" +
148+ "[End of the messages]\n\n" +
149+ "The user writes to several agents in #general, who answer one after the other in this order: @alice, @bob. You are @bob.\n" +
150+ "The user's message:\n" + text + "\n\n" +
151+ "Your part of it: sum it up\nDo only your part, the others do theirs. Answer directly, without your name in front."
152+ if got != want {
153+ t.Fatalf("got:\n%s\nwant:\n%s", got, want)
154+ }
155+ got = channels.SharedPrompt("alice", "#general", "@alice @bob compare", []string{"alice", "bob"}, nil)
156+ if strings.Contains(got, "Your part") || !strings.Contains(got, "You are @alice.") {
157+ t.Fatalf("a request for everyone has no part:\n%s", got)
158+ }
159+}
@@ -111,3 +111,49 @@ func TestReferencesAreTheFilesJoinedWithADollar(t *testing.T) {
111 }111 }
112 }112 }
113 }113 }
114+
115+func TestPartForIsWhatFollowsTheAgentsMention(t *testing.T) {
116+ addressed := []string{"alice", "bob"}
117+ text := "@alice make a story about seven of nine, then @bob make a summary of this story"
118+ cases := map[string]string{"alice": "make a story about seven of nine, then", "bob": "make a summary of this story"}
119+ for agent, want := range cases {
120+ if got := channels.PartFor(text, agent, addressed); got != want {
121+ t.Errorf("%s: got %q, want %q", agent, got, want)
122+ }
123+ }
124+ shared := map[string]string{
125+ "@alice and @bob, tell me a joke": "alice", // one word: the request is for both
126+ "@alice @bob compare": "bob",
127+ "tell me @bob`@alice`": "alice", // a mention in code is text
128+ }
129+ for text, agent := range shared {
130+ if got := channels.PartFor(text, agent, addressed); got != "" {
131+ t.Errorf("%q for %s: got %q, want nothing", text, agent, got)
132+ }
133+ }
134+ if got := channels.PartFor("@alice and @bob, tell me a joke", "bob", addressed); got != "tell me a joke" {
135+ t.Errorf("got %q", got)
136+ }
137+ // Only the agents that answer cut a part: @carol is just text here.
138+ if got := channels.PartFor("@alice ask @carol about trains", "alice", addressed); got != "ask @carol about trains" {
139+ t.Errorf("got %q", got)
140+ }
141+}
142+
143+func TestSharedPromptTellsTheAgentWhoItIsAndItsPart(t *testing.T) {
144+ text := "@alice make a story, then @bob sum it up"
145+ got := channels.SharedPrompt("bob", "#general", text, []string{"alice", "bob"}, []channels.Line{{Author: "alice", Text: "Once upon a time."}})
146+ want := "[Messages in #general you have not seen yet]\n" +
147+ "alice: Once upon a time.\n" +
148+ "[End of the messages]\n\n" +
149+ "The user writes to several agents in #general, who answer one after the other in this order: @alice, @bob. You are @bob.\n" +
150+ "The user's message:\n" + text + "\n\n" +
151+ "Your part of it: sum it up\nDo only your part, the others do theirs. Answer directly, without your name in front."
152+ if got != want {
153+ t.Fatalf("got:\n%s\nwant:\n%s", got, want)
154+ }
155+ got = channels.SharedPrompt("alice", "#general", "@alice @bob compare", []string{"alice", "bob"}, nil)
156+ if strings.Contains(got, "Your part") || !strings.Contains(got, "You are @alice.") {
157+ t.Fatalf("a request for everyone has no part:\n%s", got)
158+ }
159+}
modified internal/channels/turns.go +3 -0
@@ -472,6 +472,9 @@ func (m *Manager) prompt(ch *channel, agent string, item *pending, from string,
472472 if from != "" {
473473 return HandoffPrompt(agent, from, place, unseen(ch, agent, nil, fresh))
474474 }
475+ if addressed := item.route.Agents; len(addressed) > 1 && ch.info.Direct == "" {
476+ return SharedPrompt(agent, place, textOf(item.message), addressed, unseen(ch, agent, item.message, fresh))
477+ }
475478 return Prompt(agent, place, textOf(item.message), unseen(ch, agent, item.message, fresh))
476479 }
477480
@@ -472,6 +472,9 @@ func (m *Manager) prompt(ch *channel, agent string, item *pending, from string,
472 if from != "" {472 if from != "" {
473 return HandoffPrompt(agent, from, place, unseen(ch, agent, nil, fresh))473 return HandoffPrompt(agent, from, place, unseen(ch, agent, nil, fresh))
474 }474 }
475+ if addressed := item.route.Agents; len(addressed) > 1 && ch.info.Direct == "" {
476+ return SharedPrompt(agent, place, textOf(item.message), addressed, unseen(ch, agent, item.message, fresh))
477+ }
475 return Prompt(agent, place, textOf(item.message), unseen(ch, agent, item.message, fresh))478 return Prompt(agent, place, textOf(item.message), unseen(ch, agent, item.message, fresh))
476 }479 }
477 480