<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pascal Wilbrink on Medium]]></title>
        <description><![CDATA[Stories by Pascal Wilbrink on Medium]]></description>
        <link>https://medium.com/@pascal.wilbrink?source=rss-3fdcef4aff2f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NjpvBL3zRgdLxTgY.jpg</url>
            <title>Stories by Pascal Wilbrink on Medium</title>
            <link>https://medium.com/@pascal.wilbrink?source=rss-3fdcef4aff2f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 11:37:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pascal.wilbrink/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create a Spring AI application with AG-UI]]></title>
            <link>https://medium.com/@pascal.wilbrink/create-a-spring-ai-application-with-ag-ui-4257a7e83dfb?source=rss-3fdcef4aff2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4257a7e83dfb</guid>
            <dc:creator><![CDATA[Pascal Wilbrink]]></dc:creator>
            <pubDate>Wed, 13 Aug 2025 13:02:33 GMT</pubDate>
            <atom:updated>2025-08-13T13:02:33.480Z</atom:updated>
            <content:encoded><![CDATA[<p>The intersection of Spring’s robust ecosystem and modern AI capabilities opens up exciting possibilities for building intelligent applications. In this guide, we’ll walk through integrating Spring AI with the AG-UI protocol to create powerful, agent-driven applications.</p><h3>What is AG-UI?</h3><p>AG-UI is an open protocol based on events.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mTWUeL218nRC8at_fL7gcw.png" /><figcaption><a href="https://ag-ui.com/">ag-ui.com</a></figcaption></figure><h4>Events</h4><p>AG-UI has a set of events that the protocol uses to update state. You can find more information about AG-UI events <a href="https://docs.ag-ui.com/concepts/events">here</a>.</p><h4>Agents</h4><p>AG-UI-4J has an abstract class for a LocalAgent. This class has a Spring-AI implementation.</p><h3>Create a full Agentic Spring AI application</h3><h4>Prerequisites</h4><p>Before we begin, ensure you have:</p><ul><li>Java 17 or higher</li><li>Maven 3.6+</li><li>Basic understanding of Spring Boot</li><li>An IDE of your choice</li></ul><h4>Step 1: Creating the Maven Project</h4><p>Let’s start by creating a new Maven project with the necessary Spring Boot structure:</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;<br>         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br>         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 <br>         http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;<br>    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br>    <br>    &lt;groupId&gt;com.example&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-ai-agui-demo&lt;/artifactId&gt;<br>    &lt;version&gt;1.0.0&lt;/version&gt;<br>    &lt;packaging&gt;jar&lt;/packaging&gt;<br>    <br>    &lt;parent&gt;<br>        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br>        &lt;version&gt;3.2.0&lt;/version&gt;<br>        &lt;relativePath/&gt;<br>    &lt;/parent&gt;<br>    <br>    &lt;properties&gt;<br>        &lt;maven.compiler.source&gt;17&lt;/maven.compiler.source&gt;<br>        &lt;maven.compiler.target&gt;17&lt;/maven.compiler.target&gt;<br>        &lt;spring-ai.version&gt;0.8.1&lt;/spring-ai.version&gt;<br>    &lt;/properties&gt;<br>    <br>    &lt;!-- We&#39;ll add dependencies in the next step --&gt;<br>&lt;/project&gt;</pre><h4>Step 2: Adding Spring AI Dependencies</h4><pre>&lt;dependencies&gt;<br>    &lt;!-- Spring Boot Starters --&gt;<br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>    &lt;/dependency&gt;<br>     &lt;dependency&gt;<br>        &lt;groupId&gt;org.springframework.ai&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-ai-starter-model-ollama&lt;/artifactId&gt;<br>     &lt;/dependency&gt;<br>&lt;/dependencies&gt;</pre><p>Under versions, at the latest spring-ai version (currently 1.0.1)</p><pre>    &lt;properties&gt;<br>        &lt;spring-ai.version&gt;1.0.1&lt;/spring-ai.version&gt;<br>    &lt;/properties&gt;</pre><p>In the dependencyManagement section, add spring-ai</p><pre> &lt;dependencyManagement&gt;<br>        &lt;dependencies&gt;<br>            &lt;dependency&gt;<br>                &lt;groupId&gt;org.springframework.ai&lt;/groupId&gt;<br>                &lt;artifactId&gt;spring-ai-bom&lt;/artifactId&gt;<br>                &lt;version&gt;${spring-ai.version}&lt;/version&gt;<br>                &lt;type&gt;pom&lt;/type&gt;<br>                &lt;scope&gt;import&lt;/scope&gt;<br>            &lt;/dependency&gt;<br>        &lt;/dependencies&gt;<br>    &lt;/dependencyManagement&gt;</pre><h4>Step 3: Adding ag-ui-4j from GitHub Packages</h4><p>Since ag-ui-4j is hosted on GitHub packages (for now), we need to configure Maven to access it. Add the repository configuration:</p><pre>&lt;repositories&gt;<br>    &lt;repository&gt;<br>        &lt;id&gt;github&lt;/id&gt;<br>        &lt;url&gt;https://maven.pkg.github.com/work-m8/ag-ui-4j&lt;/url&gt;<br>        &lt;snapshots&gt;<br>            &lt;enabled&gt;true&lt;/enabled&gt;<br>        &lt;/snapshots&gt;<br>    &lt;/repository&gt;<br>&lt;/repositories&gt;</pre><p>And add the AG-UI-4J (server) dependencies:</p><pre> &lt;dependency&gt;<br>     &lt;groupId&gt;io.workm8.agui4j&lt;/groupId&gt;<br>     &lt;artifactId&gt;spring-ai&lt;/artifactId&gt;<br>     &lt;version&gt;0.0.1&lt;/version&gt;<br> &lt;/dependency&gt;<br> &lt;dependency&gt;<br>     &lt;groupId&gt;io.workm8.agui4j&lt;/groupId&gt;<br>     &lt;artifactId&gt;server&lt;/artifactId&gt;<br>     &lt;version&gt;0.0.1&lt;/version&gt;<br>  &lt;/dependency&gt;<br>  &lt;dependency&gt;<br>      &lt;groupId&gt;io.workm8.agui4j&lt;/groupId&gt;<br>      &lt;artifactId&gt;spring&lt;/artifactId&gt;<br>      &lt;version&gt;0.0.1&lt;/version&gt;<br>  &lt;/dependency&gt;<br>... Other dependencies</pre><p>The io.workm8.agui4j.spring-ai package contains the SpringAiAgent that we will use to create an Agentic Spring AI application.</p><p>The io.workm8.agui4j.server package contains server related classes that we will need.</p><p>The io.workm8.agui4j.spring package contains a Spring EventEmitter service that we need for SSE(Server Sent Events) communication.</p><p>You’ll also need to configure authentication in your ~/.m2/settings.xml:</p><pre>&lt;servers&gt;<br>    &lt;server&gt;<br>        &lt;id&gt;github&lt;/id&gt;<br>        &lt;username&gt;[YOUR_GITHUB_USERNAME]&lt;/username&gt;<br>        &lt;password&gt;[YOUR_GITHUB_TOKEN]&lt;/password&gt;<br>    &lt;/server&gt;<br>&lt;/servers&gt;</pre><p>Full pom.xml</p><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;<br>         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br>         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;<br>    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;<br>    &lt;parent&gt;<br>        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;<br>        &lt;version&gt;3.5.4&lt;/version&gt;<br>        &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;<br>    &lt;/parent&gt;<br><br>    &lt;groupId&gt;org.example&lt;/groupId&gt;<br>    &lt;artifactId&gt;spring-ai-example&lt;/artifactId&gt;<br>    &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;<br><br>    &lt;properties&gt;<br>        &lt;spring-ai.version&gt;1.0.1&lt;/spring-ai.version&gt;<br>        &lt;ag-ui.version&gt;0.0.1&lt;/ag-ui.version&gt;<br>    &lt;/properties&gt;<br><br>    &lt;dependencies&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;org.springframework.ai&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring-ai-starter-model-ollama&lt;/artifactId&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;io.workm8.agui4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring-ai&lt;/artifactId&gt;<br>            &lt;version&gt;${ag-ui.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;io.workm8.agui4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;server&lt;/artifactId&gt;<br>            &lt;version&gt;${ag-ui.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>        &lt;dependency&gt;<br>            &lt;groupId&gt;io.workm8.agui4j&lt;/groupId&gt;<br>            &lt;artifactId&gt;spring&lt;/artifactId&gt;<br>            &lt;version&gt;${ag-ui.version}&lt;/version&gt;<br>        &lt;/dependency&gt;<br>    &lt;/dependencies&gt;<br><br>    &lt;dependencyManagement&gt;<br>        &lt;dependencies&gt;<br>            &lt;dependency&gt;<br>                &lt;groupId&gt;org.springframework.ai&lt;/groupId&gt;<br>                &lt;artifactId&gt;spring-ai-bom&lt;/artifactId&gt;<br>                &lt;version&gt;${spring-ai.version}&lt;/version&gt;<br>                &lt;type&gt;pom&lt;/type&gt;<br>                &lt;scope&gt;import&lt;/scope&gt;<br>            &lt;/dependency&gt;<br>        &lt;/dependencies&gt;<br>    &lt;/dependencyManagement&gt;<br><br>    &lt;build&gt;<br>        &lt;plugins&gt;<br>            &lt;plugin&gt;<br>                &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>                &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;<br>            &lt;/plugin&gt;<br>        &lt;/plugins&gt;<br>    &lt;/build&gt;<br><br>&lt;/project&gt;</pre><h4>Step 4: Creating the initial Application</h4><p>Let’s create a simple Spring Boot application</p><pre>package com.example.application;<br><br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br><br>@SpringBootApplication<br>public class Application {<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(Application.class, args);<br>    }<br>}</pre><p>Add Jackson configuration for serializing messages:</p><pre>package com.example.application.config;<br><br>import com.fasterxml.jackson.databind.ObjectMapper;<br>import com.fasterxml.jackson.databind.SerializationFeature;<br>import io.workm8.agui4j.json.ObjectMapperFactory;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.context.annotation.Primary;<br><br>@Configuration<br>public class JacksonConfig {<br><br>    @Bean<br>    @Primary<br>    public ObjectMapper objectMapper() {<br>        ObjectMapper mapper = new ObjectMapper();<br>        mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);<br><br>        ObjectMapperFactory.addMixins(mapper);<br><br>        return mapper;<br>    }<br>}</pre><p>Cors configuration:</p><pre>package com.example.application.config;<br><br>import org.springframework.boot.web.servlet.FilterRegistrationBean;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.core.Ordered;<br>import org.springframework.web.cors.CorsConfiguration;<br>import org.springframework.web.cors.CorsConfigurationSource;<br>import org.springframework.web.cors.UrlBasedCorsConfigurationSource;<br>import org.springframework.web.filter.CorsFilter;<br><br>import java.util.Arrays;<br><br>@Configuration<br>public class CorsConfig {<br><br>    @Bean<br>    public CorsConfigurationSource corsConfigurationSource() {<br>        CorsConfiguration configuration = new CorsConfiguration();<br>        configuration.setAllowedOriginPatterns(Arrays.asList(&quot;*&quot;)); // Or specify domains<br>        configuration.setAllowedMethods(Arrays.asList(&quot;GET&quot;, &quot;POST&quot;, &quot;PUT&quot;, &quot;DELETE&quot;, &quot;OPTIONS&quot;));<br>        configuration.setAllowedHeaders(Arrays.asList(&quot;*&quot;));<br><br>        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();<br>        source.registerCorsConfiguration(&quot;/**&quot;, configuration);<br>        return source;<br>    }<br><br>    @Bean<br>    public FilterRegistrationBean&lt;CorsFilter&gt; corsFilter() {<br>        FilterRegistrationBean&lt;CorsFilter&gt; bean = new FilterRegistrationBean&lt;&gt;(<br>                new CorsFilter(corsConfigurationSource())<br>        );<br>        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);<br>        return bean;<br>    }<br>}</pre><p>AG-UI configuration:</p><pre>package com.example.application.config;<br><br>import com.fasterxml.jackson.databind.ObjectMapper;<br>import io.workm8.agui4j.server.spring.AgUiService;<br>import io.workm8.agui4j.server.streamer.AgentStreamer;<br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br><br>@Configuration<br>public class AgUiConfig {<br><br>    @Bean<br>    public AgentStreamer agentStreamer() {<br>        return new AgentStreamer();<br>    }<br><br>    @Bean<br>    public AgUiService agUiService(ObjectMapper objectMapper) {<br>        return new AgUiService(agentStreamer(), objectMapper);<br>    }<br>}</pre><h4>Step 5: Create the Agent classes.</h4><p>First, we will create an agent controller.</p><pre>package com.example.application.agent;<br><br>import io.workm8.agui4j.server.spring.AgUiParameters;<br>import io.workm8.agui4j.server.spring.AgUiService;<br>import io.workm8.agui4j.spring.ai.SpringAIAgent;<br>import org.springframework.ai.chat.client.ChatClient;<br>import org.springframework.ai.ollama.OllamaChatModel;<br>import org.springframework.ai.ollama.api.OllamaApi;<br>import org.springframework.ai.ollama.api.OllamaOptions;<br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.http.CacheControl;<br>import org.springframework.http.ResponseEntity;<br>import org.springframework.stereotype.Controller;<br>import org.springframework.web.bind.annotation.PathVariable;<br>import org.springframework.web.bind.annotation.PostMapping;<br>import org.springframework.web.bind.annotation.RequestBody;<br>import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;<br><br>import java.util.ArrayList;<br><br>@Controller<br>public class AgentController {<br><br>    private final AgentService agentService;<br><br>    @Autowired<br>    public AgUiController(<br>        final AgentService agentService<br>    ) {<br>        this.agentService = agentService;<br>    }<br><br>    @PostMapping(value = &quot;/agents/{agentId}&quot;)<br>    public ResponseEntity&lt;SseEmitter&gt; streamData(@PathVariable(&quot;agentId&quot;) final String agentId, @RequestBody() final AgUiParameters agUiParameters) {<br>        return null;<br>    }<br><br>}</pre><p>We will implement the controller method later.</p><p>Let’s create the AgentService first:</p><pre>package com.example.application.agent;<br><br>import io.workm8.agui4j.server.LocalAgent;<br>import io.workm8.agui4j.server.spring.AgUiParameters;<br>import io.workm8.agui4j.server.spring.AgUiService;<br>import io.workm8.agui4j.spring.ai.SpringAIAgent;<br>import org.springframework.ai.chat.client.ChatClient;<br>import org.springframework.ai.ollama.OllamaChatModel;<br>import org.springframework.ai.ollama.api.OllamaApi;<br>import org.springframework.ai.ollama.api.OllamaOptions;<br>import org.springframework.http.HttpStatusCode;<br>import org.springframework.stereotype.Service;<br>import org.springframework.web.client.HttpClientErrorException;<br>import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;<br><br>import java.util.ArrayList;<br>import java.util.List;<br><br>@Service<br>public class AgentService {<br><br>    private final AgUiService agUiService;<br><br>    private List&lt;LocalAgent&gt; agents;<br><br>    @Autowired<br>    public AgentService(<br>        final AgUiService agUiService<br>    ) {<br>        this.agUiService = agUiService;<br><br>        this.agents = new ArrayList();<br>    }<br><br>    public SseEmitter runAgent(final String agentId, final AgUiParameters parameters) {<br>      return null;<br>    }<br><br>}</pre><p>In this example, we will use a simple local list of agents.</p><p>Now, let’s connect the controller to the service:</p><pre>@PostMapping(value = &quot;/sse/{agentId}&quot;)<br>public ResponseEntity&lt;SseEmitter&gt; streamData(@PathVariable(&quot;agentId&quot;) final String agentId, @RequestBody() final AgUiParameters agUiParameters) {<br>    SseEmitter emitter = this.agentService.runAgent(agentId, agUiParameters);<br><br>    return ResponseEntity<br>        .ok()<br>        .cacheControl(CacheControl.noCache())<br>        .body(emitter);<br>}</pre><h4>Step 6: Set up a SpringAIAgent</h4><p>Let’s create a new SpringAIAgent in our AgentService .</p><p>In this example, we will use Ollama as the llm provider and llama3.2 as the llm.</p><pre>@Autowired<br>public AgentService(<br>    final AgUiService agUiService<br>) {<br>    this.agUiService = agUiService;<br><br>    var chatModel = OllamaChatModel.builder()<br>        .defaultOptions(OllamaOptions.builder().model(&quot;llama3.2&quot;).build())<br>        .ollamaApi(OllamaApi.builder().baseUrl(&quot;http://localhost:11434&quot;).build())<br>        .build();<br><br>    this.agents = List.of(<br>        new SpringAIAgent(<br>            &quot;1&quot;,<br>            ChatClient.builder(chatModel).build(),<br>            new ArrayList&lt;&gt;()<br>        )<br>    );<br>}<br><br>public SseEmitter runAgent(final String agentId, final AgUiParameters parameters) {<br>    var agent = this.agents<br>        .stream()<br>        .filter(a -&gt; a.getAgentId().equals(agentId))<br>        .findFirst()<br>        .orElseThrow(() -&gt; new HttpClientErrorException(HttpStatusCode.valueOf(404), &quot;Agent with id &#39;%s&#39; not found&quot;.formatted(agentId)));<br><br>    return this.agUiService.runAgent(agent, parameters);<br>}</pre><h4>Full Service</h4><pre>package com.example.application.agent;<br><br>import io.workm8.agui4j.server.LocalAgent;<br>import io.workm8.agui4j.server.spring.AgUiParameters;<br>import io.workm8.agui4j.server.spring.AgUiService;<br>import io.workm8.agui4j.spring.ai.SpringAIAgent;<br>import org.springframework.ai.chat.client.ChatClient;<br>import org.springframework.ai.ollama.OllamaChatModel;<br>import org.springframework.ai.ollama.api.OllamaApi;<br>import org.springframework.ai.ollama.api.OllamaOptions;<br>import org.springframework.http.HttpStatusCode;<br>import org.springframework.stereotype.Service;<br>import org.springframework.web.client.HttpClientErrorException;<br>import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;<br><br>import java.util.ArrayList;<br>import java.util.List;<br><br>@Service<br>public class AgentService {<br><br>    private final AgUiService agUiService;<br><br>    private List&lt;LocalAgent&gt; agents;<br><br>    public AgentService(<br>        final AgUiService agUiService<br>    ) {<br>        this.agUiService = agUiService;<br><br>        var chatModel = OllamaChatModel.builder()<br>            .defaultOptions(OllamaOptions.builder().model(&quot;llama3.2&quot;).build())<br>            .ollamaApi(OllamaApi.builder().baseUrl(&quot;http://localhost:11434&quot;).build())<br>            .build();<br><br>        this.agents = List.of(<br>            new SpringAIAgent(<br>                &quot;1&quot;,<br>                ChatClient.builder(chatModel).build(),<br>                new ArrayList&lt;&gt;()<br>            )<br>        );<br>    }<br><br>    public SseEmitter runAgent(final String agentId, final AgUiParameters parameters) {<br>        var agent = this.agents.stream().filter(a -&gt; a.getAgentId().equals(agentId))<br>            .findFirst()<br>            .orElseThrow(() -&gt; new HttpClientErrorException(HttpStatusCode.valueOf(404), &quot;Agent with id &#39;%s&#39; not found&quot;.formatted(agentId)));<br><br>        return this.agUiService.runAgent(agent, parameters);<br>    }<br>}</pre><h4>Step 7: Set up our client</h4><p>We will use <a href="https://copilotkit.ai/">copilotkit</a> to create a client. For more information about how to set up copilotkit, you can check out the <a href="https://docs.copilotkit.ai/mastra/quickstart?agent=bring-your-own">documentation here</a>.</p><pre>npx create-next-app@latest my-copilot-app<br>cd my-copilot-app</pre><pre>npm install @copilotkit/react-ui @copilotkit/react-core @copilotkit/runtime @ag-ui/http</pre><pre>/* api/copilotkit/route.ts */<br>import {<br>  CopilotRuntime,<br>  ExperimentalEmptyAdapter,<br>  copilotRuntimeNextJSAppRouterEndpoint,<br>} from &quot;@copilotkit/runtime&quot;;<br><br>import { HttpClient } from &quot;@ag-ui/http&quot;<br>import { NextRequest } from &quot;next/server&quot;;<br><br>const serviceAdapter = new ExperimentalEmptyAdapter();<br><br>// Our Spring AI agent endpoint<br>const agent: HttpAgent = new HttpAgent({<br>  url: &#39;http://localhost:8080/agents/1&#39;<br>});<br><br>const runtime = new CopilotRuntime({<br>  agents: {<br>    agent<br>  }<br>});<br> <br>export const POST = async (req: NextRequest) =&gt; {<br>  const { handleRequest } = copilotRuntimeNextJSAppRouterEndpoint({<br>    runtime, <br>    serviceAdapter,<br>    endpoint: &quot;/api/copilotkit&quot;,<br>  });<br> <br>  return handleRequest(req);<br>};</pre><pre>/* app/layout.tsx */<br><br>import { CopilotKit } from &quot;@copilotkit/react-core&quot;; <br>import &quot;@copilotkit/react-ui/styles.css&quot;;<br><br>export default function RootLayout({ children }: {children: React.ReactNode}) {<br>  return (<br>    &lt;html lang=&quot;en&quot;&gt;<br>      &lt;body&gt;<br><br>        &lt;CopilotKit <br>          runtimeUrl=&quot;/api/copilotkit&quot; <br>          agent=&quot;agent&quot;<br>        &gt;<br>          {children}<br>        &lt;/CopilotKit&gt;<br>      &lt;/body&gt;<br>    &lt;/html&gt;<br>  );<br>}</pre><pre>/* app/page.tsx */<br><br>import { CopilotSidebar } from &quot;@copilotkit/react-ui&quot;; <br> <br>export default function Page() {<br>  return (<br>    &lt;main&gt;<br>      &lt;h1&gt;Your App&lt;/h1&gt;<br>      &lt;CopilotSidebar /&gt;<br>    &lt;/main&gt;<br>  );<br>}</pre><h3>Conclusion</h3><p>By combining Spring AI’s powerful AI capabilities with the ag-ui protocol’s agent-based interface framework, you can build sophisticated, intelligent applications that provide natural user interactions. This integration allows you to leverage Spring’s dependency injection, configuration management, and ecosystem while providing a standardized way to build agent-driven UIs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4257a7e83dfb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>