Hubspot Dynamic Multi Agent System
HubSpot Dynamic Multi-Agent System with Magistral Reasoning
This cookbook demonstrates the power of Magistral reasoning model combined with HubSpot CRM integration to create an intelligent, multi-agent system that can understand complex business queries and execute sophisticated CRM operations automatically.
The system transforms natural language business questions into actionable insights and automated CRM updates, showcasing how advanced AI reasoning can streamline sales operations and strategic decision-making.

Problem Statement
Traditional CRM Challenges
Modern sales and marketing teams face several critical challenges when working with CRM systems like HubSpot:
Manual Data Analysis: Teams spend hours manually analyzing deals, contacts, and companies to extract insights Complex Query Processing: Business stakeholders struggle to get answers to multi-faceted questions that require data from multiple CRM objects Strategic Planning: Market analysis and expansion planning requires combining CRM data with business intelligence in ways that aren't natively supported
Sample Query
"Assign priorities to all deals based on deal value"
These queries require:
- Understanding business context
- Analyzing multiple data sources
- Applying business logic
- Generating actionable recommendations
- Sometimes updating CRM records automatically
Solution Architecture
Core Innovation: Magistral Reasoning + HubSpot Integration + Multi-Agent Orchestration
Our solution combines Mistral's Magistral reasoning model with HubSpot's comprehensive CRM API through a sophisticated multi-agent system that can:
- Understand complex business queries using Magistral's advanced reasoning capabilities
- Plan multi-step execution strategies with dynamically created specialized agents
- Execute both data analysis and CRM updates through coordinated agent workflows
- Synthesize results into actionable business insights with strategic recommendations
AgentOrchestrator
Master coordinator that manages the entire multi-agent workflow and HubSpot integration. Orchestrates the complete flow from query analysis through sub-agent execution to final synthesis, while managing agent lifecycle and data connectivity.
LeadAgent
Powered by Magistral reasoning model with <think> pattern processing, the Lead Agent performs sophisticated query analysis to understand business intent, determine data requirements, and create detailed execution plans specifying which sub-agents to create dynamically.
Dynamic Sub-Agents
Sub-agents are created on-the-fly based on specific query requirements - not pre-defined templates. Each agent is dynamically generated with specialized roles (e.g., priority_calculator, market_analyzer, deals_updater), specific tasks, and targeted data access patterns using Mistral Small for fast execution.
HubSpot API Connector
Dedicated connector providing comprehensive access to CRM data and operations:
- Property Discovery: Automatically maps all available HubSpot fields and valid values
- Data Fetching: Retrieves deals, contacts, and companies with full property sets
- Batch Updates: Efficiently updates multiple records in batches of 100
SynthesisAgent
Final orchestrator that combines all sub-agent results into coherent, actionable business insights using Mistral Small. Transforms technical agent outputs into user-friendly responses with strategic recommendations and next steps.

Installation
We need hubspot-api-client and mistralai packages for the demonstration.
Collecting hubspot-api-client Downloading hubspot_api_client-12.0.0-py3-none-any.whl.metadata (9.3 kB) Collecting mistralai Downloading mistralai-1.9.3-py3-none-any.whl.metadata (37 kB) Requirement already satisfied: requests>=2.31.0 in /usr/local/lib/python3.11/dist-packages (from hubspot-api-client) (2.32.3) Requirement already satisfied: urllib3<3.0,>=1.15 in /usr/local/lib/python3.11/dist-packages (from hubspot-api-client) (2.5.0) Requirement already satisfied: six<2.0,>=1.10 in /usr/local/lib/python3.11/dist-packages (from hubspot-api-client) (1.17.0) Requirement already satisfied: certifi>=2023.1.1 in /usr/local/lib/python3.11/dist-packages (from hubspot-api-client) (2025.7.14) Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from hubspot-api-client) (2.9.0.post0) Collecting eval-type-backport>=0.2.0 (from mistralai) Downloading eval_type_backport-0.2.2-py3-none-any.whl.metadata (2.2 kB) Requirement already satisfied: httpx>=0.28.1 in /usr/local/lib/python3.11/dist-packages (from mistralai) (0.28.1) Requirement already satisfied: pydantic>=2.10.3 in /usr/local/lib/python3.11/dist-packages (from mistralai) (2.11.7) Requirement already satisfied: typing-inspection>=0.4.0 in /usr/local/lib/python3.11/dist-packages (from mistralai) (0.4.1) Requirement already satisfied: anyio in /usr/local/lib/python3.11/dist-packages (from httpx>=0.28.1->mistralai) (4.9.0) Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.11/dist-packages (from httpx>=0.28.1->mistralai) (1.0.9) Requirement already satisfied: idna in /usr/local/lib/python3.11/dist-packages (from httpx>=0.28.1->mistralai) (3.10) Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.11/dist-packages (from httpcore==1.*->httpx>=0.28.1->mistralai) (0.16.0) Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.11/dist-packages (from pydantic>=2.10.3->mistralai) (0.7.0) Requirement already satisfied: pydantic-core==2.33.2 in /usr/local/lib/python3.11/dist-packages (from pydantic>=2.10.3->mistralai) (2.33.2) Requirement already satisfied: typing-extensions>=4.12.2 in /usr/local/lib/python3.11/dist-packages (from pydantic>=2.10.3->mistralai) (4.14.1) Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests>=2.31.0->hubspot-api-client) (3.4.2) Requirement already satisfied: sniffio>=1.1 in /usr/local/lib/python3.11/dist-packages (from anyio->httpx>=0.28.1->mistralai) (1.3.1) Downloading hubspot_api_client-12.0.0-py3-none-any.whl (4.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.3/4.3 MB 43.8 MB/s eta 0:00:00 Downloading mistralai-1.9.3-py3-none-any.whl (426 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 426.3/426.3 kB 17.6 MB/s eta 0:00:00 Downloading eval_type_backport-0.2.2-py3-none-any.whl (5.8 kB) Installing collected packages: eval-type-backport, hubspot-api-client, mistralai Successfully installed eval-type-backport-0.2.2 hubspot-api-client-12.0.0 mistralai-1.9.3
Imports
Setup API Keys
Setup MistralAI Client
HubSpot API connector
-
get_data: Fetches CRM data from HubSpot API, Retrieves deals, contacts, and companies data for the analysis. -
batch_update: Performs batch updates to HubSpot records, the updates and writes them back to HubSpot in efficient batches of 100 records. -
get_properties: Automatically fetches and formats all HubSpot deal, contact, and company properties, including valid values and dropdown options, so agents can update data reliably without errors.
Magistral (reasoning) and Mistral small LLM functions
-
magistral_reasoning: Uses Magistral reasoning model for complex query analysis and execution planning with thinking process. -
mistral_small_execution: Uses Mistral Small model for sub-agent task execution.
LeadAgent
Powered by Magistral reasoning model for sophisticated query analysis and execution planning
analyze_query: Uses Magistral's<think>pattern to understand business intent, determine data requirements, and create detailed execution plans with dynamic sub-agent specifications- Determines whether queries require read-only analysis or write-back operations to HubSpot
SubAgent
Dynamic agents created on-the-fly based on query complexity and requirements
execute: Uses Mistral Small for fast task execution including data analysis, business logic application, and CRM updates- Specialized roles generated automatically (e.g., priority_calculator, market_analyzer, deals_updater)
- Handles both read-only operations and write-back operations with proper HubSpot property validation
SynthesisAgent
Final orchestrator that combines all sub-agent results into coherent business insights
synthesize: Uses Mistral Small to create user-friendly responses with actionable recommendations and next steps- Transforms technical agent outputs into executive-ready summaries and strategic guidance
AgentOrchestrator
Master coordinator that manages the entire multi-agent workflow and HubSpot integration
process_query: Orchestrates the complete flow from query analysis through sub-agent execution to final synthesis- Manages agent lifecycle, data flow between agents, and HubSpot connectivity
- Provides rich logging and monitoring of the multi-agent process
Initialize the multi-agent system
📡 HubSpotConnector: Loading properties... ✅ HubSpotConnector: Loaded properties for 3 object types 📡 HubSpotConnector: Fetching deals data... ✅ HubSpotConnector: Loaded 5 deals 📡 HubSpotConnector: Fetching contacts data... ✅ HubSpotConnector: Loaded 5 contacts 📡 HubSpotConnector: Fetching companies data... ✅ HubSpotConnector: Loaded 5 companies 🚀 AgentOrchestrator: System initialized with 15 HubSpot records
Test Queries
Query-1
🎯 Processing Query: Assign priorities to all deals based on deal value.... ================================================================================ 🧠 LeadAgent: Analyzing query with Magistral reasoning... ✅ LeadAgent: Plan created - 2 sub-agents needed 🤖 deal_data_fetcher (read_only): Executing task... ✅ deal_data_fetcher: Task completed successfully 🤖 priority_assigner (write_back): Executing task... 📡 HubSpotConnector: Updating 5 deals... ✅ HubSpotConnector: deals updates completed ✅ priority_assigner: Successfully updated HubSpot records ✅ priority_assigner: Task completed successfully 🔄 SynthesisAgent: Synthesizing results from 2 agents... ✅ SynthesisAgent: Final answer synthesized ================================================================================ ✨ Query processing completed!
HubSpot status before updation

HubSpot status after updation

Dynamically Created Agents
Answer
Query-2
🎯 Processing Query: We're considering expanding into three new industry verticals and need comprehensive market
inte...
================================================================================
🧠 LeadAgent: Analyzing query with Magistral reasoning...
✅ LeadAgent: Plan created - 6 sub-agents needed
🤖 Customer Success Analysis Agent (read_only): Executing task...
✅ Customer Success Analysis Agent: Task completed successfully
🤖 Market Opportunity Analysis Agent (read_only): Executing task...
✅ Market Opportunity Analysis Agent: Task completed successfully
🤖 Competitive Landscape Analysis Agent (read_only): Executing task...
✅ Competitive Landscape Analysis Agent: Task completed successfully
🤖 Ideal Customer Profile Agent (read_only): Executing task...
✅ Ideal Customer Profile Agent: Task completed successfully
🤖 Market Size and Penetration Agent (read_only): Executing task...
✅ Market Size and Penetration Agent: Task completed successfully
🤖 Market Entry Strategy Agent (read_only): Executing task...
✅ Market Entry Strategy Agent: Task completed successfully
🔄 SynthesisAgent: Synthesizing results from 6 agents...
✅ SynthesisAgent: Final answer synthesized
================================================================================
✨ Query processing completed!