Skip to content

Self-improving AI Employees for everyone

fix(chat): Reply in Chat with no message posts the agent's answer

trohitg73b23421397b
diff --git a/docs-internal/node-logic-flows/chat_utility/chatReply.md b/docs-internal/node-logic-flows/chat_utility/chatReply.md
index 8906637b..efa9b22a 100644
--- a/docs-internal/node-logic-flows/chat_utility/chatReply.md
+++ b/docs-internal/node-logic-flows/chat_utility/chatReply.md
@@ -24,7 +24,7 @@ Turn on Talk and the shipped example workflows wire it after an agent, with
| Handle | Connection type | Required | Purpose |
|--------|-----------------|----------|---------|
-| `input-main` | main | no | The agent whose answer it posts. The answer is read through the `message` template, not through connected outputs: the node is not in `NodeExecutor._NEEDS_CONNECTED_OUTPUTS`. |
+| `input-main` | main | no | The agent whose answer it posts. The answer is read through the `message` template; with `message` empty, from the connected output (`connected_outputs`, since the node is in `NodeExecutor._NEEDS_CONNECTED_OUTPUTS`). |
`hide_output_handle = True`, so it renders as a sink with only `input-main`,
like `console`. It does not carry console's `isConsoleSink` hint.
@@ -33,7 +33,7 @@ like `console`. It does not carry console's `isConsoleSink` hint.
| Name | Type | Default | Required | displayOptions.show | Description |
|------|------|---------|----------|---------------------|-------------|
-| `message` | string (3 rows, placeholder `{{agent.response}}`) | `""` | no | - | The text to post, usually a template such as `{{aiagent.response}}`. A whole-value template keeps the upstream value's type, so a dict or list arrives as-is and is posted as JSON text; `None` becomes empty. |
+| `message` | string (3 rows, placeholder `{{agent.response}}`) | `""` | no | - | The text to post, usually a template such as `{{aiagent.response}}`. A whole-value template keeps the upstream value's type, so a dict or list arrives as-is and is posted as JSON text; `None` becomes empty. Empty posts what the connected agent answered. |
`model_config = ConfigDict(extra="ignore")`.
@@ -59,7 +59,7 @@ like `console`. It does not carry console's `isConsoleSink` hint.
```mermaid
flowchart TD
- A[Receive params: message coerced to text] --> B[text = message.strip]
+ A[Receive params: message coerced to text] --> B[text = message.strip,<br/>else the connected output's response / message / text / content]
B --> C{empty, or exactly NO_REPLY?}
C -- yes --> D[Return posted=false: nothing written or broadcast]
C -- no --> E{ctx.workflow_id set?}
@@ -81,6 +81,10 @@ flowchart TD
- **Coercion** (`field_validator(mode="before")` on `message`): `None` -> `""`,
a dict or list -> `json.dumps(..., ensure_ascii=False, default=str)`,
anything else -> `str(...)`.
+- **No message**: an empty `message` posts what the node's input answered:
+ the first connected output's `response` (an agent's answer), else its
+ `message`, `text` or `content`. So an agent wired to it in the editor needs no
+ template; before, its answer streamed into the chat and then vanished.
- **Nothing to say**: after trimming, an empty text or exactly `NO_REPLY`
(`services.approvals.contract.NO_REPLY`, what an agent answers when it has
nothing to send) posts nothing and succeeds with `posted: false`. The edges
diff --git a/server/nodes/chat/chat_reply/__init__.py b/server/nodes/chat/chat_reply/__init__.py
index 9449e800..96772fb8 100644
--- a/server/nodes/chat/chat_reply/__init__.py
+++ b/server/nodes/chat/chat_reply/__init__.py
@@ -6,8 +6,11 @@ the assistant. The owner reads it in Talk on the employee's Home page and
in the editor's chat pane. The write goes through services/chat_thread.py,
which stamps the live generation and announces ``chat.updated``.
-A message that is empty, or exactly NO_REPLY (the agent had nothing to
-say), posts nothing. A ``<followups>`` block the answer ends with is never
+With ``message`` empty it posts what the node's input answered: the
+connected agent's ``response`` (``connected_outputs``, which NodeExecutor
+gives this node), so an agent wired in the editor needs no template. An
+answer that is empty, or exactly NO_REPLY (the agent had nothing to say),
+posts nothing. A ``<followups>`` block the answer ends with is never
shown as text: in a chat run it becomes the reply's follow-up buttons
(``services/chat/guide.py``), elsewhere it is dropped.
@@ -38,6 +41,7 @@ from services.plugin import ActionNode, NodeContext, NodeUserError, Operation, T
class ChatReplyParams(BaseModel):
message: str = Field(
default="",
+ description="What to post. Empty posts what the connected agent answered.",
json_schema_extra={"rows": 3, "placeholder": "{{agent.response}}"},
)
@@ -57,6 +61,24 @@ class ChatReplyParams(BaseModel):
return str(value)
+_ANSWER_FIELDS = ("response", "message", "text", "content")
+
+
+def _connected_answer(raw: Any) -> str:
+ """What the node's input answered: the first connected output's
+ ``response`` (an agent's answer), else its ``message``, ``text`` or
+ ``content``."""
+ outputs = raw.get("connected_outputs") if isinstance(raw, dict) else None
+ for output in outputs.values() if isinstance(outputs, dict) else ():
+ if not isinstance(output, dict):
+ continue
+ for field in _ANSWER_FIELDS:
+ value = output.get(field)
+ if isinstance(value, str) and value.strip():
+ return value
+ return ""
+
+
class ChatReplyOutput(BaseModel):
#: False when there was nothing to post.
posted: bool = False
@@ -92,7 +114,7 @@ class ChatReplyNode(ActionNode):
from services.chat_thread import record_chat_message
from services.plugin.deps import get_database
- text = params.message.strip()
+ text = params.message.strip() or _connected_answer(ctx.raw).strip()
# The <followups> block an answer may end with shows as buttons, never
# as text: a message that is only the block says nothing.
visible = split_followups(text)[0].strip()
diff --git a/server/services/node_executor.py b/server/services/node_executor.py
index d837a4e3..a8e059fd 100644
--- a/server/services/node_executor.py
+++ b/server/services/node_executor.py
@@ -317,6 +317,7 @@ class NodeExecutor:
"console",
"socialReceive",
"canvas",
+ "chatReply",
}
)
diff --git a/server/tests/nodes/test_chat_reply.py b/server/tests/nodes/test_chat_reply.py
index 70653a10..ed90a367 100644
--- a/server/tests/nodes/test_chat_reply.py
+++ b/server/tests/nodes/test_chat_reply.py
@@ -59,6 +59,28 @@ async def test_nothing_to_say_posts_nothing(harness, thread, message):
assert thread.frames == []
+async def test_with_no_message_it_posts_what_the_connected_agent_answered(harness, thread):
+ # Wired from an agent in the editor without a template, the answer used
+ # to stream in and then vanish: the node posted nothing.
+ nodes = [{"id": "a", "type": "aiAgent"}, {"id": "r", "type": "chatReply"}]
+ edges = [{"source": "a", "target": "r", "sourceHandle": "output-main", "targetHandle": "input-main"}]
+
+ async def reply(answer):
+ context = harness.build_context(
+ workflow_id="wf-1", nodes=nodes, edges=edges, upstream_outputs={"a::output_main": {"response": answer, "model": "m"}}
+ )
+ return await harness.execute("chatReply", {"message": ""}, node_id="r", context=context)
+
+ result = await reply(" Booked you for 3pm. ")
+ harness.assert_envelope(result, success=True)
+ assert thread.database.add_chat_message.await_args.args[2] == "Booked you for 3pm."
+ # An agent with nothing to say still posts nothing.
+ thread.database.add_chat_message.reset_mock()
+ result = await reply("NO_REPLY")
+ assert result["result"]["posted"] is False
+ thread.database.add_chat_message.assert_not_awaited()
+
+
async def test_an_answer_that_is_not_text_is_posted_as_text(harness, thread):
# A whole-value template keeps the upstream value's type.
result = await _reply(harness, {"items": ["milk", "eggs"]})