Events provide visibility into agent execution and enable reactive behavior. Each event type has specific input structure, output requirements, and use cases.
History Structure
All events provide access to state.history, an array of HistoryStep objects tracking execution flow.
HistoryStep Structure
step: Sequential step number
type: Step type (TRIGGER_NODE, TOOL_NODE, LLM_NODE, etc.)
// Query a knowledge base during trigger qualification
//
// Use this pattern when you want full control over *when* retrieval happens
// and *how* the retrieved context is applied to the conversation.
import { SystemMessage } from '@langchain/core/messages';
import { v4 as uuidv4 } from 'uuid';
import { retrieveFromKnowledgeBase } from '@minded-ai/mindedjs';
agent.on(events.TRIGGER_EVENT, async ({ triggerBody, state }) => {
const query = typeof triggerBody?.content === 'string' ? triggerBody.content : JSON.stringify(triggerBody);
// knowledgeBaseId is optional - backend auto-selects if agent has exactly 1 KB
// Pass knowledgeBaseId explicitly if you have multiple KBs
const { retrievalResults } = await retrieveFromKnowledgeBase({
environment: 'production',
query,
numberOfResults: 5,
});
if (retrievalResults.length > 0) {
const context = retrievalResults.map((r) => `#### ${r.location.s3Location.uri}\n${r.content.text}`).join('\n\n');
state.messages.push(
new SystemMessage({
id: uuidv4(),
content: `### Knowledge Base Context\n\n${context}`,
}),
);
}
return { isQualified: true };
});
{
error: Error;
state: State<Memory>;
}
{
throwError: boolean; // true = throw error and stop, false = catch and continue
}