Skip to content
Apixo
Blog
news· 3 min read· via Towards AI

Building a Spec-Driven AI Wealth Manager with PyAgent, GraphQL, and Oracle Math

Developer Saurabh Kohli demonstrates how combining PyAgent blueprints, fixed GraphQL queries, and deterministic tax libraries creates reliable multi-agent systems.

Building a Spec-Driven AI Wealth Manager with PyAgent, GraphQL, and Oracle Math

A recent open-source experiment highlights a growing trend in AI engineering: restricting language models to tasks they excel at while offloading arithmetic and business logic to deterministic code. Developer Saurabh Kohli built a spec-driven multi-agent wealth management system, published in the repository wealth-agent, to test whether combining PyAgent blueprints, fixed GraphQL queries, and specialized Python libraries could produce reliable portfolio rebalancing recommendations. The project demonstrates how shifting from prompt-heavy architectures to validated specifications eliminates common agent failures like skipped steps or hallucinated API parameters.

Replacing Prompt Reasoning with Deterministic Logic

During initial testing, handing financial calculations and regulatory compliance directly to LLMs led to significant reliability issues. The tax-focused worker failed at basic gain and loss arithmetic across complex cost bases. Similarly, relying on prompt instructions for compliance checks created inconsistent pass-or-fail decisions on identical trade sets.

To resolve these errors, Kohli removed model calculations entirely from those steps. The tax optimization pipeline now formats input data for Oracle, a specialized Python library that handles tax-aware portfolio math deterministically. For compliance, the system executes plain Python rules using simple-rule-engine to verify concentration limits and wash-sale rules. Transitioning both steps to code eliminated calculation errors, made outputs perfectly repeatable, and saved approximately $0.02 in model fees per run.

A similar pattern emerged with data fetching. Initially, the market worker used REST endpoints that returned large 10KB payloads, consuming unnecessary context space. When switched to free-form GraphQL, the model began inventing non-existent schema fields like priceHistory and beta. By locking the worker into a fixed GraphQL query template where only ticker variables can change, token usage dropped by 60 percent and invented fields fell to zero.

Workflow Governance and Execution Tracing

System orchestration is managed by PyAgent through a single blueprint.yaml configuration file. This manifest defines agent roles, primary and small providers (such as openai:gpt-5.6-sol for supervisor work and openai:gpt-5.6-luna for output synthesis), worker contracts, and execution budgets.

Early versions suffered from workflow drift. When stage order was governed solely by system prompts, the supervisor model occasionally skipped mandatory steps, twice generating final recommendations without running compliance checks. Moving the workflow order into the blueprint manifest solved the issue, preventing execution from reaching synthesis until all prerequisite stages pass.

To manage worker failures—such as an agent looping on a non-existent tool—the blueprint enforces a maximum token budget of 60,000 per run. Full execution visibility is handled by pyagent-trace, which logs every model call, tool execution, and associated cost to a JSONL event bus. If a final plan contains errors, developers can replay the recorded run step-by-step rather than guessing what went wrong during runtime.

What it means for developers

This experiment offers several actionable insights for software engineers building complex, multi-agent pipelines:

  • Keep math outside the LLM: Models struggle with multi-lot tax calculations and deterministic boolean checks. Use dedicated algorithms or libraries for calculation steps, reserving models for input formatting and final prose generation.
  • Constrain tool parameters: Instead of allowing agents to write arbitrary database or API queries, provide rigid query templates with bounded variables to stop schema hallucination and reduce payload size.
  • Enforce workflow state in specs: Prompt instructions can be ignored under context load. Control execution flow, stage gates, and token budgets through static specifications validated before runtime.
  • Implement granular tracing: Log model calls, adapter inputs, and token spending to an event stream to simplify debugging when pipelines produce incorrect recommendations.

When constructing multi-agent setups, selecting the right model for each specific sub-task is critical for both reliability and cost efficiency. Developers looking to benchmark or deploy different model providers across their workflow stages can try top AI models cheaply through one API at https://apixoai.online.

By reserving language models for semantic parsing and natural language summarization—while placing hard limits on tool access and execution order—developers can build multi-agent systems that remain predictable under production constraints.


Source: Spec-Driven AI Wealth Manager — Towards AI. Written by the Apixo team from that report.

#ai-news#ai-agents#pyagent#graphql#python#llm-architecture
Try it with your own tools

One key for Claude, GPT, GLM, DeepSeek and more. Pay per token with crypto.

Get your API key

Keep reading