Realtime Compute for Apache Flink supports developing event-driven, streaming AI agent jobs based on the open-source Apache Flink Agents framework. This document explains the core concepts of Flink Agents, covering version requirements, a quick-start guide, custom development, job submission, and dependency management.
Overview
Apache Flink Agents is a new subproject from the Apache Flink community for building event-driven AI agents. It leverages Flink's battle-tested streaming engine to bring distributed, stateful, fault-tolerant, and streaming capabilities to AI agents, making them ready for enterprise production environments.
Flink Agents includes built-in modules for large language model (LLM) calls, tool usage, memory management, dynamic orchestration, and observability. With these features, you can quickly build large-scale, continuously running, and reliable production-grade AI agents.
Flink Agents provides the following core advantages:
|
Capability |
Description |
|
Distributed coordination |
The framework provides core capabilities like event routing, partitioning, distributed state consistency, and automated failure recovery, which eliminates the need to manage multiple agent replicas. |
|
Stateful memory |
Flink State manages agent memory, which is automatically persisted, restored, and redistributed during checkpoints. This eliminates the need for an external storage system to maintain state consistency. |
|
Stream processing |
As events continuously arrive, agents respond in real time. Flink's stream processing engine provides a high-throughput, low-latency core for this operational model. |
|
Production reliability |
Distributed checkpoints enable automatic recovery from node failures with exactly-once processing guarantees, ensuring no data or event loss. |
Agent types
You can build Workflow or ReAct agents for different use cases.
|
Type |
Use cases |
Description |
|
Workflow Agent |
Scenarios with well-defined processes |
Orchestrates agent behavior through a predefined, event-driven workflow. For more information, see Workflow Agent. |
|
ReAct Agent |
Scenarios requiring flexible decision-making |
Combines Reasoning and Action, allowing an LLM to autonomously determine the execution steps. For more information, see ReAct Agent. |
Versions and models
-
When you submit a Flink Agents job, select VVR engine version VVR-11.8.preview.2 or later. Otherwise, the job fails due to missing runtime dependencies.
VVR engine version
Flink version
Flink Agents version
vvr-11.8.preview.2-jdk11-flink-1.20
1.20
0.2.1
-
The models are provided by the platform. You do not need to apply for a separate API key to call them in your job. This feature is in Beta and requires access via an allowlist. For more information, see Flink AI Service (Built-in Models).
Prerequisites
-
Products and permissions
-
You have activated Realtime Compute for Apache Flink and created a workspace. For more information, see Activate Realtime Compute for Apache Flink.
-
If you are using a RAM user or RAM role, you must have the necessary permissions for the Flink console. For more information, see Permission management.
-
-
Local development environment
-
Python: Python 3.10 or 3.11.
-
Java: Java 11+ and Maven 3+.
-
Quick start
This section uses a product review analysis example to walk you through the entire process. You will build a sample Flink job with a review analysis agent by using the Flink Agents framework. When the job runs, the agent calls the Model Studio large language model (LLM) service to analyze product reviews, generating a satisfaction score (from 1 to 5) and the reasons for any dissatisfaction.
Step 1: Download sample job files
Python job
Download quickstart-python.zip, which contains the following files:
|
File |
Description |
|
main.py |
The job entry point. It creates the execution environment, registers the LLM connection, and builds the stream processing pipeline. |
|
review_analysis_agent.py |
The agent implementation. It defines the prompt template, ChatModel configuration, and action-handling logic. |
You can upload the downloaded ZIP package directly without unzipping it. The Python dependencies used in this example, such as openai and dashscope, are pre-installed in the VVR engine image.
Java job
Download the following files:
|
File |
Description |
|
A test fat JAR that you can upload directly. |
|
|
The Java source code, provided for your reference. |
Step 2: Upload and deploy the job
-
Log on to the Realtime Compute for Apache Flink console.
-
In the Actions column of the target workspace, click Console.
-
In the left-side navigation pane, click File Management. Then, click Upload Resource to upload the job files that you downloaded.
-
On the Operations > Jobs page, click Deploy Job. Select Python Job or JAR Job based on your job type and fill in the deployment information.
Python job configuration
|
Parameter |
Example |
|
Deployment mode |
Streaming mode |
|
Deployment name |
flink-agents-quickstart-python |
|
Engine version |
vvr-11.8.preview.2-jdk11-flink-1.20 |
|
Python file address |
quickstart-python.zip |
|
Entry module |
quickstart.main |
|
Deployment target |
default-queue |
Java job configuration
|
Parameter |
Example |
|
Deployment mode |
Streaming mode |
|
Deployment name |
flink-agents-quickstart-java |
|
Engine version |
vvr-11.8.preview.2-jdk11-flink-1.20 |
|
JAR URI |
quickstart-java.jar |
|
Entry point class |
org.apache.flink.agents.quickstart.Main |
|
Deployment target |
default-queue |
Runtime parameters
Navigate to Deployment Details > Runtime parameter configuration > Edit > Other Configurations, and then add the Flink configuration items.
-
Python job
python.executable: python3.10 python.client.executable: python3.10 containerized.master.env.FLINK_HOME: /flink containerized.taskmanager.env.FLINK_HOME: /flinkParameter description
Parameter
Description
python.executable/python.client.executableSpecifies the Python interpreter version (for Python jobs only).
containerized.{master,taskmanager}.env.FLINK_HOMESets the
FLINK_HOMEenvironment variable for the JobManager and TaskManagers (for Python jobs only).NoteYou must configure the environment variable with both the
containerized.master.env.andcontainerized.taskmanager.env.prefixes to ensure that it is available to both the JobManager and the TaskManagers.
Step 3: Start the job and view the results
-
On the Operations > Jobs page, find your job and click Start in the Actions column.
-
In the Start Job dialog box, select stateless start and click Start.
-
The example uses an in-memory data source, so the job automatically ends after processing is complete. Wait for the status to change to finished, and then click the job name to go to the details page.
-
On the TaskManager tab, view the logs and search for the keyword
Review analysis result:to see the output.
In a production environment, you would typically use a streaming data source like Apache Kafka, and the job would run continuously.
Developing a custom agent
Installing Flink Agents
Python
We recommend that you use a virtual environment:
python3 -m venv flink-agents-env
source flink-agents-env/bin/activate
pip install flink-agents
For more information, see the Flink Agents Installation Guide.
Java
Add the following dependency to your pom.xml file:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-agents-api</artifactId>
<version>${flink-agents.version}</version>
<scope>provided</scope>
</dependency>
Flink Agents dependencies must be declared with <scope>provided</scope> because they are provided by the VVR engine.
To debug in your local IDE, add the following dependency:
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-agents-ide-support</artifactId>
<version>${flink-agents.version}</version>
<scope>provided</scope>
</dependency>
Writing the agent
The core structure of a Flink Agents job is as follows:
-
Register an LLM connection: Register a ChatModel connection by using the
AgentsExecutionEnvironment. Connection information, such as the API key and endpoint URL, is configured through aResourceDescriptor. For more information, see Chat Models. -
Define the agent: Implement your custom agent, configure its prompt template, and define the event-handling logic by using the
@action(Python) or@Action(Java) annotation. -
Build the pipeline: Connect the input data stream to the agent for processing and output the analysis results.
For more information about concepts such as agent, prompt, tool, and memory, see the Flink Agents development documentation.
Testing locally
Local testing is handled automatically by a Flink MiniCluster, so you do not need to deploy a separate cluster.
Python
python your_agent_job.py
Java
mvn exec:java -Dexec.mainClass="com.example.YourAgentJob"
For more information, see the Flink Agents deployment documentation.
Dependency management
Pre-installed dependencies
The VVR engine image comes pre-installed with the Flink Agents core libraries and some related dependencies.
Python dependencies
|
Dependency |
Description |
|
flink-agents core library |
The Flink Agents Python API |
|
openai |
OpenAI-compatible interface (includes the Model Studio platform) |
|
dashscope |
Alibaba Cloud Model Studio (native interface for Qwen) |
|
mcp |
Model Context Protocol |
Dependencies that are not pre-installed must be uploaded with your job. For more information, see Manage Python dependencies.
Java dependencies
The VVR engine image comes pre-installed with Flink Agents and its built-in LLM integrations. You only need to package third-party dependencies that are not built in into your job JAR.
Managing Java job dependencies
Use the maven-shade-plugin to package your job into a fat JAR. Configure the dependency scope according to the following rules:
-
Flink Agents core dependencies (such as
flink-agents-apiandflink-agents-runtime): Set the scope to<scope>provided</scope>and do not package them into the fat JAR. -
Flink core dependencies (such as
flink-streaming-java): Set the scope to<scope>provided</scope>. -
LLM integration dependencies: Handle these based on the following cases.
-
For integrations already supported by the Flink Agents community (such as OpenAI and Anthropic): Set the scope to
<scope>provided</scope>and do not package them into the fat JAR. For a complete list of integrations supported in Flink Agents 0.2.1, see Built-in Providers. -
For integrations not yet supported by the community: Set the scope to
<scope>compile</scope>and package them into the fat JAR.
-
-
Libraries that conflict with Flink (such as Jackson): Configure relocation in the
maven-shade-plugin.
For a complete pom.xml configuration example, see the quickstart-java-src.zip file.
Submitting jobs to Realtime Compute for Flink
Python job
The submission process is the same as for a standard PyFlink job. For more information, see Develop a Python job. The key parameters are as follows:
|
Parameter |
Description |
|
Engine version |
Select a VVR engine version that supports Flink Agents. For specific versions, see the "Versions and models" section. |
|
Python file address |
The job's entry Python file or ZIP package. |
|
Entry module |
The entry module name for the ZIP package. |
|
Python libraries |
Additional dependencies. |
Java job
The submission process is the same as for a standard Flink JAR job. For more information, see Develop a JAR job. The key parameters are as follows:
|
Parameter |
Description |
|
Engine version |
Select a VVR engine version that supports Flink Agents. For specific versions, see the "Versions and models" section. |
|
JAR URI |
The path to the fat JAR. |
|
Entry point class |
The fully qualified name of the job's entry class. |
Common runtime parameters
Python interpreter version
The VVR engine image defaults to Python 3.9, but Flink Agents requires Python 3.10 or 3.11. You must configure the following for a Python job:
python.executable: python3.10
python.client.executable: python3.10
containerized.master.env.FLINK_HOME: /flink
containerized.taskmanager.env.FLINK_HOME: /flink
Custom environment variables
If your job code reads configuration from environment variables (such as an endpoint URL or model selection), you must set the variables for both the JobManager and TaskManager processes by using their respective prefixes:
containerized.master.env.<ENV_VAR_NAME>: <value>
containerized.taskmanager.env.<ENV_VAR_NAME>: <value>
Example of switching models:
containerized.master.env.OPENAI_MODEL: qwen3.6-flash
containerized.taskmanager.env.OPENAI_MODEL: qwen3.6-flash