Static prompt templates are no longer enough for deep financial intelligence analysis. An agent needs to act dynamically: querying internal graphs first, turning to vector search index documentation for context, and failing back to real-time web engines like Tavily.
Here, we map the design patterns of a robust agentic orchestration pipeline.
The Routing brain
Our orchestrator functions as a loop, checking incoming user questions from webhook requests or Matrix chat messages. We structure routing using the following algorithm:
- Deconstruct user query: Extract tickers and temporal parameters.
- Execute Database Traversal: If query parameters correspond to connected graph concepts.
- Execute Vector Search: If retrieving unstructured context (such as PDFs, income statements).
- Web search fallback: If query requires real-time facts (e.g. current day’s price movements).
def query_agent(user_prompt):
# Route query using LLM logic
decision = route_query(user_prompt)
if decision == "graph":
return run_cypher_traversal(user_prompt)
elif decision == "vector":
return search_vector_embeddings(user_prompt)
else:
return run_tavily_search(user_prompt)
Why Self-Correction Matters
When generating database queries (such as Cypher), agents frequently make syntax errors (e.g., mismatching relationship direction).
Rather than returning a blank screen or throwing a stack trace to the user, we build a validation loop that passes syntax failures back to the LLM along with the DB schema definition, asking the model to fix and re-run.
This makes AI agents significantly more reliable for production dashboard applications.