* This article is written by Dr. Frederik Schubert, Dr Emerson Melo, and Dr. Qing Hu.
As the complexity of photonic systems increases, determining how to run complex simulations efficiently and affordably has become a key challenge. Leveraging a general-purpose AI tool offers a learning shortcut and saves time. However, suppose you ask a general AI agent to generate a simulation model using Tidy3D. In that case, it will output a bunch of lines of Python code, e.g. the following output from ChatGPT. They might be useful, but not strictly follow the Tidy3D documentation or have the right tools to effectively help you in different scenarios such as learning, customizing/creating a simulation setup, or analyzing simulation results.
import numpy as np, tidy3d as td, tidy3d.web as web, gdstklda0=1.55; freqs=td.C_0/np.linspace(1.5,1.6,101); f0=td.C_0/lda0; fwidth=0.5*(freqs.max()-freqs.min())si=td.material_library["cSi"]["Palik_Lossless"]; sio2=td.material_library["SiO2"]["Palik_Lossless"]t=0.22; w1=0.5; w2=0.5; w3=0.6; w4=0.7; w5=0.9; w6=1.26; w7=w8=w9=w10=1.4; w11=1.31; w12=w13=1.2l_in=1; l_junc=2; l_bend=6; h_bend=2; l_out=1; inf_eff=100x=np.linspace(l_in,l_in+l_junc,13); y=np.array([w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12,w13])x=np.concatenate((x,np.flipud(x))); y=np.concatenate((y/2,-np.flipud(y/2))); V=np.transpose(np.vstack((x,y)))junction=td.Structure(geometry=td.PolySlab(vertices=V,axis=2,slab_bounds=(0,t)),medium=si)xs=l_in+l_junc; x=np.linspace(xs,xs+l_bend,100)y=(x-xs)*h_bend/l_bend-h_bend*np.sin(2*np.pi*(x-xs)/l_bend)/(2*np.pi)+w13/2-w1/2x=np.append(x,inf_eff); y=np.append(y,y[-1]); cell=gdstk.Cell("bends")...
Then, what is an ideal AI agent for simulation?
It is the integration of the Large Language Models (LLMs), instructions, and tools. The LLMs handle pre-training, post-training, and reinforcement learning based on human feedback and verified rewards.
So, how to get the most useful AI assistants for simulation-related tasks?
We have made this happen - FlexAgent MCP, which, unlike generic coding assistants, understands Tidy3D workflows and integrates with Cursor or VS Code AI agents to provide physics-aware assistance for electromagnetic simulations. The FlexAgent MCP provides a natural language-driven workflow for learning, troubleshooting, customizing, or analyzing Tidy3D simulations. It is accessible via the Tidy3D extensions for Cursor and VS Code, which also incorporate a user-friendly 3D Viewer for inspecting simulation setups.
π‘ What is MCP?
π What is FlexAgent MCP?
π€ FlexAgent - the AI-powered assistance tool
MCP stands for Model Context Protocol and is a standard that defines how to interact with Large Language Models (LLMs), which serve as the foundation of current AI systems. The main goal of the protocol is to establish a text-based schema for communicating with external tools, such as APIs or local software. Many MCP servers exist, and users can select from several AI clients that support MCP.
After a MCP server is added to a MCP clientβs configuration, each conversation with the AI agent through that client includes a hidden prefix (similar to the system prompt) that describes the available tools to the agent. The agent then decides when to generate the MCP signature that triggers an external tool execution (e.g. the agent might generate mcp__flexagent__search "how to use tidy3d?" if there is a tool called search by an MCP server called flexagent. This highlights a limitation of this approach: adding too many MCP servers and tools can confuse the agent. Another key point is that adding an MCP injects arbitrary (potentially malicious) context into your AI agent, which can pose a security risk. This is less of a concern for our own FlexAgent MCP but more relevant for other MCP servers you might add.
The FlexAgent MCP is part of the flexagent-services API and deployed on AWS EC2. It exposes one tool called search_flexcompute_docs which allows it to search the documentation of Tidy3d , Photonforge , and Flow360 and external libraries such as gdstk and other future additions (If you need some software as part of your development workflow that is not well supported by current LLMs out-of-the-box, you can propose it for addition to that list).
One crucial aspect of MCPs is PROMOTING. The AI agent wonβt use the MCP unless the current query matches the advertised functionality of the MCP server. Use the phrase Use flexagent to ... to trigger the usage of the FlexAgent MCP. A more convenient way is to create a AGENTS.md file to instruct the AI agent to do this without manual intervention.
So, FlexAgent MCP is essentially an π€ AI-powered assistance tool - a Physics-informed assistance feature that integrates Tidy3D MCP with Cursor, VS Code, and other platforms as an extension. The FlexAgent MCP - Tidy3D extension enables a fully code-free, natural language-aware workflow for setting up, running, and analyzing photonic simulations. Youβll see how AI can learn from existing examples, generate new simulations, and visualize results.
Watch the video below for a demo of how Tidy3D extension performs a mode analysis step-by-step.
AI-Enhanced Workflows β Agent assistance with Tidy3D expertise through integrated MCP server
Structured Assistance β Step-by-step guidance from learning to optimization
Trusted Knowledge Base β Direct integration with Tidy3D's comprehensive documentation
Editor-Native Viewer β No context switching between tools
Live Code Synchronization β See geometry changes instantly as you type
AI-Controlled Visualization β Let the agent navigate and explain the 3D scene
FlexAgent is a physics-informed assistance through the Cursor or VS Code agents and MPC integration. The extension integrates with Cursor's agent to provide physics-aware assistance for electromagnetic simulations. Unlike generic coding assistants, this integration understands Tidy3D workflows and can control the 3D viewer.
The command Tidy3D: Run Tidy3D Workspace Setup deploys FlexAgent rules under .cursor/rules/ that transform the agent into a physics-aware simulation partner. These are structured workflows relying on Tidy3D's trusted documentation.
Learning - "How to set up a GaussianBeam source", "Explain how the FDTD method works", "How can I perform a mode analysis?"
Troubleshooting - *"Fix the warning related to 'structures[0]' extending exactly to simulation edges"*, "Fix the code to avoid the warning related to Bloch vector", "Clear the validation error related to ModeSolver plane"
Customization - "Add a mode source at the position (-4, 0, 0) to inject the fundamental TE waveguide mode at 1.55 micrometers" - "Build a mode simulation setup to analyze the dispersion parameters of the first 2 optical modes at the source plane of my FDTD simulation setup" - "Perform a parameter sweep to vary the unit cell period between 0.3 to 0.5 micrometers"
Build from Scratch - "Create a simple FDTD simulation setup to simulate a silicon strip waveguide with dimensions (0.5, 0.22, 10) and refractive index of 3.47", "I am interested in PIC devices. Build a setup to obtain the modal power at the outputs of a y-junction waveguide. Add s-bends to the output waveguides", "I want to build a simulation setup to investigate structural color generation"
Result Analysis - "Plot the field intensity profile obtained from the FieldMonitor at the central frequency", "Considering my parameter sweep simulation, plot the |E|^2 field profile for all the modes in the largest waveguide", "Plot the reflectance spectrum of all unit cell period values in the parameter sweep simulation in a single chart"
Leverage FlexAgent rules for optimal results β For best performance, explicitly reference the integrated rules: *"Follow the FlexAgent rules in `flexagent.mdc` for all responses. These rules take priority over other instructions."*
Start simple, build incrementally β Begin with basic simulations and add complexity step by step for easier debugging and understanding.
Provide rich context with specific details in your queries β The more specific you are, the better FlexAgent's assistance will be. Instead of "help with mode analysis," try: "I'm studying photonic integrated circuits. How can I use Tidy3D to analyze the fundamental TE mode of a 220 nm thick silicon strip waveguide?"
Use the viewer for real-time iteration β Keep the 3D viewer open while editing your simulation code. Changes to geometry, materials, sources, or monitors are updated automatically, allowing you to immediately visualize the impact of parameter tweaks without re-running the code.
Be specific when troubleshooting β Instead of "fix all errors," provide targeted information: *"Fix the boundary condition warning for structure[0]"* or "Resolve the mesh refinement issue near the waveguide core."
Understand before proceeding β Take time to comprehend the generated code and simulation setup. Ask FlexAgent to explain concepts you're unfamiliar with before building upon them.
Use incremental validation β After each major change, ask FlexAgent to "validate and explain the simulation changes" before proceeding to ensure physical accuracy.
Document your simulation intent β Add comments explaining the physics you're trying to model: `# Modeling evanescent coupling between two strip waveguides separated by 200 nm`
Specify your Python environment β Tell FlexAgent which environment to use: *"Run this code using my `tidy3d_latest` conda environment located at `/home/user/miniconda3/envs/tidy3d_latest`."*
Learning
- "How to set up a GaussianBeam source"
- "Explain how the FDTD method works"
- "How can I perform a mode analysis?"
Troubleshooting
- *"Fix the warning related to 'structures[0]' extending exactly to simulation edges"*
- "Fix the code to avoid the warning related to Bloch vector"
- "Clear the validation error related to ModeSolver plane"
Customization
- "Add a mode source at the position (-4, 0, 0) to inject the fundamental TE waveguide mode at 1.55 micrometers"
- "Build a mode simulation setup to analyze the dispersion parameters of the first 2 optical modes at the source plane of my FDTD simulation setup"
- "Perform a parameter sweep to vary the unit cell period between 0.3 to 0.5 micrometers"
Build from scratch
- "Create a simple FDTD simulation setup to simulate a silicon strip waveguide with dimensions (0.5, 0.22, 10) and refractive index of 3.47"
- "I am interested in PIC devices. Build a setup to obtain the modal power at the outputs of a y-junction waveguide. Add s-bends to the output waveguides"
- "I want to build a simulation setup to investigate structural color generation"
Analysis
- "Plot the field intensity profile obtained from the FieldMonitor at the central frequency"
- "Considering my parameter sweep simulation, plot the |E|^2 field profile for all the modes in the largest waveguide"
Sign up today to explore the most intelligent simulation workflow ever built.