https://discord.gg/botpress logo
Is it possible to use autonomous node to exit if i...
# 🀝help
w
Im looking to leverage the conversation within the autonomous node to handle customer queries I want to hand it off to webhook (n8n) when it cannot find the answer within the KB in botpress. I can handle it when it meets the condition but cannot when it cant https://cdn.discordapp.com/attachments/1433545292384436245/1433545292753670274/image.png?ex=69051497&is=6903c317&hm=ae35b4e2fc000803dbfa60106d5c67c5a5267c799b87cca7d8b733fa7e85a3b4&
w
what do you mean by cannot when it can't?
w
when it cant find the answer in the KB I want to handle the task off to another node - I cant seem to get it to fire the transition on failure
w
i think that can be pretty easily resolved with some changes to your transitions and agent
how do you do that currently?
w
See screenshot above
it looks to transition current when the turn.knowledgeagent.responded is false
w
is the ! in the right place? i usually place it oustide the variable
about your title, i managed that with this small prompt
Copy code
answer the user's questions. if you cannot answer three questions, take the "handoff" transition to hand the conversation off to a human.
then a transition with
take this transition when you cannot answer three questions
the agent keeps track of how many questions it has failed to answer then takes the transition itself
w
in the condition of transition I have added {{!turn.KnowledgeAgent.responded}}
w
does the agent have access to that variable?
w
well it seems like it's a condition error
because responded does exist
it's just empty
you could do length = 0 or something else but that won't help with your "x attempts" mechanic
w
but empty var means turn,knowledgeagent.responded is true??
w
yes
length 0 is truthy
so it should be true
i think the problem is that the exclamation mark should be outisde
!{{turn.KnowledgeAgent.responded}}
also
w
ill try this approach and see but wanted to understand the mechanics of why my logic didnt apply
w
the correct syntax is !turn.KnowledgeAgent.responded
try that
transitions don't need jinja i'm fairly sure
w
standby1
w
it didn't apply because turn.KnowledgeAgent.responded is true, because - responded is an empty array - an empty array is truthy so if you get an empty array (no answer), turn.KnowledgeAgent.responded is true
if you DO get an answer, it's also true
the agent probably also needs access to the variable in the "Variable Access" section
so the correct transition would be turn.KnowledgeAgent.responded.length == 0
but that doesn't account for the "after x attempts"
w
seems to work now with some adjustments on instructions I think
instructions I provided was: ## Identity You are the Customer Support AI Agent for x Your role is to interact with customers, identify what product their query relates to (platformx or platformy) assistance with common support topics. ## Response Style - Maintain a friendly, clear, and professional tone. - Keep responses brief and to the point. - Use buttons for quick replies and easy navigation whenever possible. ## Guardrails - **Privacy**: Respect customer privacy; only request personal data if absolutely necessary. - **Accuracy**: Provide verified and factual responses coming from Knowledge Base or official sources. Avoid speculation. ## Instructions - **Greeting**: Start every conversation with a friendly welcome. if you cannot answer after two questions, take the "KB_Fallback Node" transition to hand the conversation off to backup node. - **Closing**: End interactions by confirming that the customer's issue has been addressed. _Example_: "Is there anything else I can help you with today?"
And the condition states: !{{turn.KnowledgeAgent.responded}}
So Im not sure which condition is firing
w
i think it would be better if you just use natural language on everything in autonomous nodes
instead of conditions
especially since your current one evaluates to "true" in all cases
w
I think so too
w
the agent depends on the transition and vice versa, they are not separate
w
it never seems to meet the condition
w
can you try the snippets i sent before? they worked pretty well in my test
they could help you too
w
Yeah see above I added to my general instructions and its firing jsut slightly erracticly eg after 2 or 3 invalid responses
w
yes because of your transitioon condition
the variable name is invalid and so is the condition, since the response is never "none" or "null"
just empty, which evaluates to "true"
it's not a javascript condition, the agent takes it based on reasoning
w
aye that was my understanding in the end
w
which is why it's erratic
w
yeah ill take that its further than I was - have you ever handed off call from botpress to n8n webhook
w
yes i use n8n a lot on my workflows
w
idea is that it will transition from botpress kb to n8n which as some workflow to precess files added in google drive
w
couldn't you add those google drive files to the botpress kb?
that would surely help
w
Can botpress "listen to google drive"
I want to build up the KB organically
w
what do you mean by that?
do you want to selectively add stuff from gdrive into the kb?
instead of everything
w
yeah so Im listening to specific folder in n8n
I dont see this option in botpress
it wants to have it added to kb directly it seems
w
well you can add to the KB directly from n8n
"directly"
w
I use pinecone as the kb in n8n
w
oh okay
now i'm a bit confused
your connection is botpress > n8n > pinecone
and you want to keep two separate kbs?
w
Sooooo
N8n works with g chat and slack for basic rag search
Im planning that if the site that botpress is loaded onto doesnt have the answer then it will failback to the n8n instance to find the data -> if that doesnt have it then you get access to service desk to log tkt
essentailly creating 2 barriers of knpwledge around the service desk
w
okay so i guess you can just use execute code to axios post the question to n8n pinecone?
and return webhook with the response
i don't know how the hell slack ties into all that
but i trust you
then a switch after that to trigger a handoff to service desk
w
slack for internal staff botpress for customers
makes the support scalable
w
hmm i think i get the gist
i can help you with any of those steps
what do you need?
w
webhook presentation between botpress and n8n
w
what do you want to pass to n8n and what do you need to receive from it
w
when calling webhook does hook provide the answer back
the question that couldnt be answered
w
and how does pinecone respond when there's no answer?
"no answer", "none", null, empty
w
id have to validate initally want to see if I can get the fallback kb to provide the answer
w
ok i'm gonna draw a little flowchart on figma
if the botpress kb can answer, it answers if it cannot, it queries n8n through a webhook, then looks in pinecone
if it finds an answer in pinecone, it returns it and botpress answers it if it doesn't, it returns a command to botpress to hand the conversation off to service desk
the main code is very simple, you just use
await axios.post('your-n8n-webhook-url', {question: event.preview})
to pass the question to your webhook
also set your webhook to respond "with respond to webhook node" instead of "instantly"
w
exactly
w
alright feel free to test that snippet out
to see if it works for you
w
Ive ran out of time tonight but will provide feedback tomorrow thanks for your help tonight
w
no problem!! have a good night
w
hi shen
seem to have an issue hitting the n8n webhook is there something that has to be done in advance to allow access to it from botpress
I can hit it via the browser but getting all sorts of errors when I try hit via the bot
w
what errors are you getting?
w
429 and 404
rror card:"Webhook Sender with Retry Logic for Botpress Integration" action Webhook POST failed. Error: Request failed with status code 404 Webhook POST failed. Error: Request failed with status code 404 {"scope":"bot-action","cardId":"card:\"Webhook Sender with Retry Logic for Botpress Integration\"","nodeId":"node:KB_Fallback_/_Handoff","workflowId":"flow:Main"}
w
429 is a botpress error when you make too many requests in the emulator
404 is because your endpoint is wrong
keep in mind n8n has two different endpoints for each webhook
one is "webhook", one is "webhook-test" i think
so the webhook-test only works when you click listen for test event
there's "test url" and "production url"
w
Its def the right endpoint its a simple poc to ensure comms and points to https://n8.skillsims.com/webhook/e067e033-f6b7-4439-935c-ce4ac1b8f96c
w
is it not n8n.skillsims?
w
no hit the link and it will throw up a rando message
w
well 404 just means the webhook url is wrong
or your workflow is not active
if the webhook is set to "test url", the endpoint only exists if you're listening for a test event
if the webhook is set to "production url", your workflow must be active for it to work
by the way you don't need the two blocks, you can just set your webhook to respond immediately
and then delete the second respond one
w
i know but easier to update later if I have the two for processing in the middle
url as above is live no test and it responds in the browser so it must be live?
Have to assume firewall or something blocking bot traffic to it
w
true true
can you check on the top right?
gray for inactive and green for active
try doing a test event first though
w
click on the link
its def live
w
@white-activity-34212 i think the problem could be on the webhook integration you're using
i reallly don't use it, kind of a headache
just make a simple
await axios.post('your-n8n-webhook-url', {question: event.preview})
in a custom event
or are you already using it?
w
no was using code execute
w
can you send me the code so i can check?
also please check using the test url instead of the prod one
w
custom event worked
well didnt error
n hit the n8n
w
nice then
it'll just respond instantly since you have nothin
w
how should i handle the response now using the custom event
w
well you can just run the custom event and then look at the response payload structure
then use event.payload.username for example
w
hmm seems to be error Error while executing integration action: An unexpected error occurred in the integration. Bot owners: Check logs for more informations. Integration owners: throw a RuntimeError to return a custom error message instead.. The action error will be ignored since you are running in the Studio. Error while executing integration action: An unexpected error occurred in the integration. Bot owners: Check logs for more informations. Integration owners: throw a RuntimeError to return a custom error message instead.. The action error will be ignored since you are running in the Studio. {"scope":"dm"}
think the n8n executions where us loading in the browser directly
w
can you check the logs?
so i can see the exact error
w
are the logs only available when running the bot in the studio
or what is location of bots when using the live agent
type text channel channel preview what time integration webchat messageId da9115e4-ae02-4d86-a188-37540306480d origin workflow://wf-main/node/nd-5ae8b3461e/card/ins-e0de076e48 payload { "type": "text", "text": "what time", "metadata": { "clientMessageId": "WES2A0Kp-oPm3ClbiaVyB" } } arguments { "conversationId": "conv_01K8VAHNT1FNYPAXJ1J82WWTYG", "event": "await axios.post('https://n8.skillsims.com/webhook/e067e033-f6b7-4439-935c-ce4ac1b8f96c', {question: event.preview})" } message An error occured while executing an integration action: zs: An unexpected error occurred in the integration. Bot owners: Check logs for more informations. Integration owners: throw a RuntimeError to return a custom error message instead. stack ROOT [Running – 3844ms] └─┬ Incoming Event: webchat/channel/text [what time] [Running – 3843ms] β”œβ”€β”€ Agent: VisionAgent/conversation_turn_started [Done – 0ms] β”œβ”€β”¬ Card: Main/Start/transition #1 [Done – 0ms] β”‚ └── Transition: true [Done – 0ms] β”œβ”€β”¬ Hook: before_llmz_execution/inject_learnings [Done – 190ms] β”‚ └─┬ User Code: 1t0a6cd (20 lines) [Done – 131ms] β”‚ └── Integration Action: agi/improvement/findFeedback [Done – 129ms] β”œβ”€β”¬ LLMZ Iteration #llmz_01K90X5RWV2YXHASMFZZ57Z7H3_1 [workflow://wf-main/node/nd-54aa0c19de] [Done – 3251ms] β”‚ β”œβ”€β”€ nodes/autonomous/AutonomousNode [Done – 3116ms] β”‚ └── Tool: workflow.transition [Done – 1ms] β”œβ”€β”¬ Hook: after_llmz_execution/track_iterations [Done – 260ms] β”‚ └─┬ User Code: fua228 (20 lines) [Done – 204ms] β”‚ └── Integration Action: agi/improvement/trackIterations [Done – 202ms] β”œβ”€β”¬ Card: Main/AutonomousNode/tmp-transition [Done – 1ms] β”‚ └── Transition: true [Done – 0ms] └─┬ Card: Main/KB_Fallback_/_Handoff/Send Custom Event #1 [Running – 79ms] └── Integration Action: webchat/customEvent [Running – 78ms] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
w
yes
that one doesn't help unfortunately
w
IS event.preview definately available at this point
keeping in mind it hasnt been able to find info
w
no because the request never completed
so event preview isnt set
w
is there a sample payload I can add like test
w
well sure
you can just check the return
do event.payload
or event
w
so {question: event}
w
no
user.question (or whatever scope) = event
w
pretty sure its gotta be firewall - ill check with the guys tried https://webhook.site/1d00226d-190b-4c5b-b8a0-603a2621e563 and no error