https://discord.gg/botpress logo
Switch Model Type of Knowledge Agent Dynamically
# 🤝help
d
I would like some flows to use a better llm while others use a smaller llm when using the knowledge agent for rag. Is there currently any way i can do that?
p
Yeah here's how you can do it in hooks:
Copy code
js
const isMainFlow = event.state.context.currentFlow.includes('main')  //<--- The flow location
const isOrchestrator = event.state.context.currentNode.includes('1e9baaf49d') //<-- the node id
console.log('Current Model: ', context.model) //<-- console log the id name of the LLM to know what to use in the next block
  if (isMainFlow && isOrchestrator) { //<-- if flow equals the flow your AN is in AND the NodeID matches the AN you want to change the LLM for
    context.model = 'openai__gpt-4.1-2025-04-14' <-- change the LLM model to the LLM id you want (line 3)
    console.log('New Model: ', context.model) //<-- console log the result to see if it applied
  }
d
@prehistoric-airplane-85682 event.state.context does not seem to have a 'model' key: whats the hook point of this?
note im using the query knowledge base card, so none of the hook options are triggering when event.state.context has a key model
p
Can you elaborate on what you are trying to achieve please?
d
@prehistoric-airplane-85682 on the botpress studio, when i enter a specific flow, i would like the LLM of the Knowledge Agent to be changed. For example a flow that handles complex queries might need a better LLM than another flow that handles standard queries and needs a faster one, both for the "query knowledgebase" card.
im trying to trigger the change based on the transition to a specific flow
b
I am trying to do this too!
have you found a solution for it? ><
2 Views