Before We Start
To follow along, you’ll need an OpenAI API key. We’ll be using OpenAI as our LLM provider throughout our agent and eventually for our evals.Follow along with code: This guide has a companion codebase with runnable code examples. Find it here.
Step 1: Set Up Phoenix Cloud
Before we can send traces anywhere, we need Phoenix running. In this step, we’ll create a Phoenix Cloud account and configure it for our application. If you’d rather run Phoenix locally, you can follow the local setup guide instead.Create a Phoenix Cloud Account
- Make a free Phoenix Cloud account.
- From the dashboard, click Create a Space in the upper-right corner.
- Enter a name for your new space.
- Once the space is created, launch your Phoenix instance directly from the dashboard.
- Create and save an API key. We’ll use this in the next step.
- Note your Hostname — this is the endpoint we’ll configure in code shortly.
Step 2: Configure your Environment
Now that Phoenix is running, we need to connect our application to it so we can start sending traces. We’ll start with an empty Mastra directory. Run this command in your terminal where you want your agent project to live.Install Required Dependencies
Set Your .env File
Connect Your Project in Phoenix
Next, we’ll register the observability layer of our application to connect to Phoenix. We can modify ourindex.ts like this:
Step 3: Create your Tools
Now that Phoenix is running and our environment is configured, we can start building the application so we can generate real execution and send traces to Phoenix. Typically we would start with creating our agents but let’s start with building our tools so that we can connect them into our agent while defining them. In this tutorial we will use Mastra, but you can build agents in any of these different frameworks for integration with Phoenix. Our application will be made up of:- One orchestrator agent: Financial Analysis Orchestrator (coordinates the workflow)
- Two sub-agents: Financial Research Analyst & Financial Report Writer
- Two tools: Financial Search Tool & Run Financial Analysis Tool
src/mastra/tools directory.
Financial Search Tool
Our first tool, the financial search tool, will be used by the research analyst. It will take in the tickers and a focus area from the user request and queries an LLM to gather financial data to then return a research summary.Financial Analysis Tool
Our second tool, the financial analysis tool, will be used by the orchestrator agent. It will take in the tickers and focus to chain the research analyst, which gathers data, and the writer agent, which generates the final report, and returns the completed report.Step 4: Create your Agent
In this step, we’ll create a simple Financial Analysis and Research chatbot. In this tutorial we will use Mastra, but you can build agents in any of these different frameworks for integration with Phoenix. We’ll now define the agents that make up our application. Within theagent directory of our project (in src/mastra), let’s make 3 files to create each of our agents: financial-orchestrator-agent.ts , financial-researcher-agent.ts, financial-writer-agent.ts.
Financial Orchestrator Agent
First, let’s define our orchestrator agent. The purpose behind this agent is to coordinate the workflow. We’ll build it to extract the important information from user inputs (to extract tickers and focus) then call the Run Financial Analysis Tool to chain the Research and Writer agents. Infinancial-orchestrator-agent.ts:
Financial Researcher Agent
Next, we can define our financial researcher agent. Its goal is to gather the financial data using the financial search tool. We can create some guidelines about what data it is supposed to focus on such as current/recent stock prices, revenue, etc. From all of this, it will produce a research summary to then give to the writer agent. Infinancial-researcher-agent.ts:
Financial Writer Agent
Lastly, we can define our finanical writer agent. This agent will compile all the Research Analyst’s findings into a well written report that addresses all focus areas, includes specific metrics, and any other guidelines we want to define. Infinancial-writer-agent.ts:
Step 5: Run Your Agent
You’ve now defined all the different parts of your multi-agent system. Before we run our chatbot for the first time, we need to connect these agents back to our Mastra object. Navigate toindex.ts and add in our agents.
index.ts will now look like:
npm run dev in your terminal to spin up the Mastra dev server. Now go into the local hosted link next to “Playground” and once in ‘Financial Analysis Orchestrator,’ ask the chatbot any question. For example: “Analyze TSLA with a focus on financial analysis and market outlook.”
Once the run completes, head back to Phoenix and navigate to the Traces view. You should see a new trace corresponding to this run. Click into it to explore how the agents and tasks are executed.
- Which agents were invoked and in what order
- How tasks flowed from one step to the next
- Where time was spent across the workflow

