I'm working with a multi-agent Agentforce setup (AgentScript / GenAiPlannerBundle) and I'm trying to guarantee that a subagent always grounds its answers in the knowledge base instead of answering from the model's own memory.
The subagent exposes a knowledge action as a tool:
AnswerQuestionsWithKnowledge:
target: "standardInvocableAction://streamKnowledgeSearch"
source: "EmployeeCopilot__AnswerQuestionsWithKnowledge"
Today it's only listed under reasoning.actions, and the instructions tell the LLM to always call it first ("never answer without calling the knowledge action"). The problem: the call is enforced only through instruction text, so the LLM skips it intermittently and answers from memory. The trace confirms the tool is in tools_sent but there's no tool_invocation on those turns.
To make the call unconditional, I tried moving it into before_reasoning:
before_reasoning:
run @actions.AnswerQuestionsWithKnowledge
with query = @system_variables.user_input
with citationsUrl = @knowledge.citations_url
with ragFeatureConfigId = @knowledge.rag_feature_config_id
with citationsEnabled = @knowledge.citations_enabled
Two issues:
- The Builder saves without any syntax error, but at runtime the agent replies with a generic "unexpected error" and nothing shows up in the trace for that action. If I remove the before_reasoning block, everything works again.
- @system_variables.user_input is rejected with a "does not exist" error in my org (even though it's in the current docs), so I'm not sure I'm referencing the user's latest message correctly.
Questions:
- Can a streaming standardInvocableAction like streamKnowledgeSearch actually be executed deterministically with run inside before_reasoning, or is that action type restricted to reasoning.actions (tool) usage only? I suspect the streaming nature may be the blocker.
- Is there a non-streaming knowledge/RAG action recommended for deterministic execution in before_reasoning/after_reasoning?
- What's the correct token for the user's latest utterance if @system_variables.user_input isn't available in my org's AgentScript version?
Has anyone successfully forced a knowledge search to run before reasoning? Any working pattern is appreciated.
Thanks!
#Agentforce #Knowledge Base
I think your overall approach is correct, but the issue may be with streamKnowledgeSearch itself.
- before_reasoning can run actions deterministically, so using run there is a valid pattern.
- In your case, AnswerQuestionsWithKnowledge uses:
standardInvocableAction://streamKnowledgeSearch
Because this is a streaming action, it looks like it may not work properly when called directly from before_reasoning. The fact that it saves successfully but fails only at runtime also points in that direction.
- I could not find clear Salesforce documentation saying that streamKnowledgeSearch is supported inside before_reasoning, so I would avoid assuming it is supported there.
- For the user message, the current documented variable is:
@system_variables.user_input
If your org says this variable does not exist, it could be related to the AgentScript version or feature rollout in that org.
For now, I would keep the Knowledge action under reasoning.actions and make the instructions as strict as possible.
If you really need the Knowledge search to run every time before reasoning, I would raise a Salesforce Support case and specifically ask whether streamKnowledgeSearch supports deterministic execution inside before_reasoning.
The interesting part here is that the script passes validation but fails only at runtime, so it may be a current platform limitation rather than an issue with your syntax.
Thank you,
Venkat Yadav.