embabel-agent icon indicating copy to clipboard operation
embabel-agent copied to clipboard

Create starter for Embabel A2A

Open alexheifetz opened this issue 1 year ago • 11 comments

Create dedicated starter for Embabel A2A components, Currently "bundled" with platform autoconfiguration which is not correct.

alexheifetz avatar Nov 20 '25 23:11 alexheifetz

I would like to give this a shot, but also I would like to understand what you mean by it being "bundled" with platform autoconfiguration?

If I recall correctly to activate a2a you have to use the profilee

abadongutierrez avatar Nov 24 '25 02:11 abadongutierrez

We're in the process of migrating profiles over to starters. AutoConfiguration maybe added if required.

Reasoning behind this decision: profile based activation is more suitable for application domain, but since we're building a framework that is being used by 3rd party applications, starters is a betters option and goes inline with Spring Boot conventions.

alexheifetz avatar Nov 24 '25 03:11 alexheifetz

There is a PR A2A Streaming PR currently under review, once it's merged we can add starter for A2A and remove @profile from the A2A configurations, services, etc.

Currently a2a module dependency is "bundled" into https://github.com/embabel/embabel-agent/blob/main/embabel-agent-autoconfigure/embabel-agent-platform-autoconfigure/pom.xml and activated via profile.

Correct approach is to move a2a dependency over to dedicated starter and remove @profile, as it not longer required.

alexheifetz avatar Nov 24 '25 03:11 alexheifetz

I see, the platform autoconfigure module is adding the embabel-agent-a2a module and that loads all configuration, bean, services, etc. because that is part of the package com.embabel.agent

so the solution we are looking for is to remove that dependency from the platform autoconfigure module and include it on the starter only

abadongutierrez avatar Nov 24 '25 03:11 abadongutierrez

is the user adds starter, that implies a2a is required and profiles are no longer needed.

alexheifetz avatar Nov 24 '25 03:11 alexheifetz

Found something interesting.

I have a fork of "embabel-agent" project where I removed the dependency embabel-agent-a2a from the platform-autoconfigure module. And I installed the jars in my local machine

Then in a cloned repo of "java-agent-template" where I modified the agent.sh script to force maven to use the current SNAPSHOTS in my local of "embabel-agent"

If I run the project I got error:

22:43:11.001 [main] INFO  ProjectNameApplication - Starting ProjectNameApplication using Java 25 with PID 20628 (C:\Users\abado\Projects\ThirdParties\java-agent-template-a2a-test\target\classes started by abado in C:\Users\abado\Projects\ThirdParties\java-agent-template-a2a-test)
22:43:11.003 [main] INFO  ProjectNameApplication - The following 1 profile is active: "starwars"
22:43:11.906 [main] WARN  AnnotationConfigApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: java.lang.IllegalStateException: Failed to introspect Class [com.embabel.agent.web.rest.GlobalExceptionHandler] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@105be200]
22:43:11.914 [main] INFO  ConditionEvaluationReportLogger - 

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
22:43:11.930 [main] ERROR SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to introspect Class [com.embabel.agent.web.rest.GlobalExceptionHandler] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@105be200]
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:360)
        at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:342)
        at org.springframework.ai.mcp.annotation.spring.AbstractClientMcpHandlerRegistry.scan(AbstractClientMcpHandlerRegistry.java:128)
        at org.springframework.ai.mcp.annotation.spring.AbstractClientMcpHandlerRegistry.postProcessBeanFactory(AbstractClientMcpHandlerRegistry.java:77)
        at org.springframework.ai.mcp.annotation.spring.ClientMcpSyncHandlersRegistry.postProcessBeanFactory(ClientMcpSyncHandlersRegistry.java:65)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:363)
        at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:204)
        at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1361)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1350)
        at com.embabel.template.ProjectNameApplication.main(ProjectNameApplication.java:28)
Caused by: java.lang.NoClassDefFoundError: jakarta/servlet/http/HttpServletRequest
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3010)
        at java.base/java.lang.Class.getDeclaredMethods(Class.java:2329)
        at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465)
        ... 15 common frames omitted
Caused by: java.lang.ClassNotFoundException: jakarta.servlet.http.HttpServletRequest
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:580)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:490)
        ... 19 common frames omitted

looks like somehow "embabel-agent-a2a" module is including web dependencies that when those are removed class "com.embabel.agent.web.rest.GlobalExceptionHandler" is failed to be instrospected because of ClassNotFoundExceptions

abadongutierrez avatar Nov 24 '25 05:11 abadongutierrez

work in progress in PR https://github.com/embabel/embabel-agent/pull/1070

abadongutierrez avatar Nov 24 '25 06:11 abadongutierrez

@abadongutierrez thanks for the observation. Most likely a2a module is bringing transitive dependencies utilized by other components.

alexheifetz avatar Nov 24 '25 21:11 alexheifetz

yes, it is, problem is that once a2a module is converted to a starter, if you want to use the shell starter instead, it will fail because of some missing web dependencies.

(I already tested this with my current changes in the PR)

abadongutierrez avatar Nov 27 '25 03:11 abadongutierrez

and actually, the build in my PR is failing because of that:

Caused by: java.lang.IllegalStateException: Failed to introspect Class [com.embabel.agent.web.rest.GlobalExceptionHandler] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@639fee48]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483)
	at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:360)
	at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:342)
	at org.springframework.ai.mcp.annotation.spring.AbstractClientMcpHandlerRegistry.scan(AbstractClientMcpHandlerRegistry.java:128)
	at org.springframework.ai.mcp.annotation.spring.AbstractClientMcpHandlerRegistry.postProcessBeanFactory(AbstractClientMcpHandlerRegistry.java:77)
	at org.springframework.ai.mcp.annotation.spring.ClientMcpSyncHandlersRegistry.postProcessBeanFactory(ClientMcpSyncHandlersRegistry.java:65)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:363)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:204)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:791)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:609)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:752)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:318)
	at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:144)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
	at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1461)
	at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:563)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:144)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:110)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:225)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:152)
	... 19 more
Caused by: java.lang.NoClassDefFoundError: org/springframework/web/servlet/NoHandlerFoundException
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3580)
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2678)
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465)
	... 40 more
Caused by: java.lang.ClassNotFoundException: org.springframework.web.servlet.NoHandlerFoundException
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	... 44 more

abadongutierrez avatar Nov 27 '25 04:11 abadongutierrez

Merged into 0.3.1-SNAPSHOT

alexheifetz avatar Nov 29 '25 04:11 alexheifetz