Node-red conversation_agent

Has anyone been using node-red to interact with the conversation_agent service? I’m able to send it data but not sure what I need to do to get a response back.

In the follow flow I, asking OpenAI to tell me a joke, it runs but I’m getting nothing back from it:

[{"id":"ed59db0d472e4b34","type":"api-call-service","z":"65a20b72.9154f4","name":"","server":"33eb04e9.d2815c","version":5,"debugenabled":true,"domain":"conversation","service":"process","areaId":[],"deviceId":[],"entityId":[],"data":"{\"agent_id\":\"119cb13531bc45d74f5c31ebf19f9c35\",\"text\":\"tell me a joke\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1180,"y":120,"wires":[["c7f75cbd5a06cd06"]]},{"id":"80213d604baac48b","type":"inject","z":"65a20b72.9154f4","name":"test","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":990,"y":120,"wires":[["ed59db0d472e4b34"]]},{"id":"c7f75cbd5a06cd06","type":"debug","z":"65a20b72.9154f4","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1400,"y":120,"wires":[]},{"id":"33eb04e9.d2815c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
1 Like

@kermit thank you very much for your reply and your suggestion will fix my next problem, getting calendar data that I can then process. However, I wasn’t at that point.

First, I am trying to pass a simple request to a conversation agent (OpenAI) ‘tell me a joke’, get the reply back from OpenAI into NodeRed so I can then do something with that data, in my exact use case I will be sending that response to a given speaker through TTS.

Did you get this sorted out? I am facing similar issues.

I did, Kermit was correct I just didnt understand that at first, here is an example that will get you going:

[{"id":"343b4f36b5cbf43f","type":"function","z":"65a20b72.9154f4","name":"Config","func":"msg.ai_response = msg.payload.response.response.speech.plain;\n\nreturn msg;\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1370,"y":220,"wires":[[]]},{"id":"34e462fa50bd4460","type":"ha-api","z":"65a20b72.9154f4","name":"","server":"33eb04e9.d2815c","version":1,"debugenabled":false,"protocol":"websocket","method":"get","path":"","data":"{\"type\":\"execute_script\",\"sequence\":[{\"service\":\"conversation.process\",\"data\":{\"agent_id\":\"AGENTID\",\"text\":\"Mary has just come home, welcome her while being funny. Do it in less than 20 words.\"},\"response_variable\":\"service_result\"},{\"stop\":\"done\",\"response_variable\":\"service_result\"}]}","dataType":"json","responseType":"json","outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"results"}],"x":1170,"y":220,"wires":[["343b4f36b5cbf43f"]]},{"id":"80213d604baac48b","type":"inject","z":"65a20b72.9154f4","name":"test","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":990,"y":120,"wires":[["34e462fa50bd4460"]]},{"id":"33eb04e9.d2815c","type":"server","name":"Home Assistant (Eoin)","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
2 Likes

Hi Eoin, this worked perfectly for me; thank you so much. In case people didn’t understand the instructions: copy Eoin’s code to your clipboard. In Node-Red, click on the menu in the upper-right, then import and paste the code. In the resulting flow edit the agent ID to your own chat-gpt agent-id. You can find this from in developer tools → services by trying out the conversation.process service in UI mode and then switching to JSON.

I also tried using conversation agent from NR. First, agent_id needs to be numeric (not the friendly name from HA; the only(?) way to get it is via sandbox → yaml mode) - this is nuts!! Second, call_service doesn’t return anything. It looks like returning functionality was added recently, waiting the next HA release.

What is the process to get the agent_id? (I can’t find the numeric name)

  • go to http://ipaddr:8123/developer-tools/service
  • select sevice: ‘conversation: process’
  • select the conversation agent you need
  • click GO TO YAML MODE

…and there it is - agent_id: xxxxxx

Afterwards, you’ll need to use API CALL node (NOT the call service node
which currently does NOT return anything; to be fixed in the next HA release?)

Thanks! Yeah we can’t do much with this for the moment.

Well, it works well enough, I use it in my automations. The alternative - gpt node in NR is lagging, no support for the latest gpt4-turbo (1106-preview).

Thank you All you save me !