-
Notifications
You must be signed in to change notification settings - Fork 993
[KYUUBI #7379][1/4] Data Agent Engine: module skeleton, configuration, and engine core #7385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
wangzhigang1999
wants to merge
4
commits into
apache:master
from
wangzhigang1999:pr1/data-agent-skeleton
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b05c88b
[KYUUBI #7379][PR 1/4] Data Agent Engine: module skeleton, configurat…
wangzhigang1999 db763c0
Fix CI: add sqlite-jdbc test dep and remove MockLlmProvider suite
wangzhigang1999 67ca188
Fix SSE event serialization: serialize toolArgs as JSON and add isErr…
wangzhigang1999 396566c
Clarify DATA_AGENT subdomain isolation rationale in EngineRef
wangzhigang1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| ~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
| ~ contributor license agreements. See the NOTICE file distributed with | ||
| ~ this work for additional information regarding copyright ownership. | ||
| ~ The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| ~ (the "License"); you may not use this file except in compliance with | ||
| ~ the License. You may obtain a copy of the License at | ||
| ~ | ||
| ~ http://www.apache.org/licenses/LICENSE-2.0 | ||
| ~ | ||
| ~ Unless required by applicable law or agreed to in writing, software | ||
| ~ distributed under the License is distributed on an "AS IS" BASIS, | ||
| ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| ~ See the License for the specific language governing permissions and | ||
| ~ limitations under the License. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.apache.kyuubi</groupId> | ||
| <artifactId>kyuubi-parent</artifactId> | ||
| <version>1.12.0-SNAPSHOT</version> | ||
| <relativePath>../../pom.xml</relativePath> | ||
| </parent> | ||
|
|
||
| <artifactId>kyuubi-data-agent-engine_${scala.binary.version}</artifactId> | ||
| <packaging>jar</packaging> | ||
| <name>Kyuubi Project Engine Data Agent</name> | ||
| <url>https://kyuubi.apache.org/</url> | ||
|
|
||
| <dependencies> | ||
| <!-- kyuubi dependency --> | ||
| <dependency> | ||
| <groupId>org.apache.kyuubi</groupId> | ||
| <artifactId>kyuubi-common_${scala.binary.version}</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.kyuubi</groupId> | ||
| <artifactId>kyuubi-ha_${scala.binary.version}</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.kyuubi</groupId> | ||
| <artifactId>${hive.jdbc.artifact}</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
|
|
||
| <!-- test dependencies --> | ||
| <dependency> | ||
| <groupId>org.apache.kyuubi</groupId> | ||
| <artifactId>kyuubi-common_${scala.binary.version}</artifactId> | ||
| <version>${project.version}</version> | ||
| <type>test-jar</type> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.xerial</groupId> | ||
| <artifactId>sqlite-jdbc</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <skipTests>${skipTests}</skipTests> | ||
| <argLine>${extraJavaTestArgs}</argLine> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-jar-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <id>prepare-test-jar</id> | ||
| <goals> | ||
| <goal>test-jar</goal> | ||
| </goals> | ||
| <phase>test-compile</phase> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| <outputDirectory>target/scala-${scala.binary.version}/classes</outputDirectory> | ||
| <testOutputDirectory>target/scala-${scala.binary.version}/test-classes</testOutputDirectory> | ||
| </build> | ||
|
|
||
| </project> |
90 changes: 90 additions & 0 deletions
90
...t-engine/src/main/java/org/apache/kyuubi/engine/dataagent/provider/DataAgentProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kyuubi.engine.dataagent.provider; | ||
|
|
||
| import java.util.function.Consumer; | ||
| import org.apache.kyuubi.config.KyuubiConf; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.AgentEvent; | ||
| import org.apache.kyuubi.util.reflect.DynConstructors; | ||
|
|
||
| /** | ||
| * A pluggable provider interface for the Data Agent engine. Implementations wire up the ReactAgent | ||
| * with an LLM model, tools, and middlewares. | ||
| */ | ||
| public interface DataAgentProvider { | ||
|
|
||
| /** Initialize a session for the given user. */ | ||
| void open(String sessionId, String user); | ||
|
|
||
| /** | ||
| * Run the agent for the given request, emitting events via the consumer. Events include | ||
| * token-level ContentDelta for streaming, ToolCall/ToolResult for tool invocations, and | ||
| * AgentFinish when complete. | ||
| * | ||
| * @param sessionId the session identifier (maps to conversation memory) | ||
| * @param request user-facing parameters (question, model override, etc.) | ||
| * @param onEvent event consumer for streaming events | ||
| */ | ||
| void run(String sessionId, ProviderRunRequest request, Consumer<AgentEvent> onEvent); | ||
|
|
||
| /** | ||
| * Close and clean up a single session, releasing session-scoped resources such as conversation | ||
| * history and session state. Called when one user session ends. | ||
| */ | ||
| void close(String sessionId); | ||
|
|
||
| /** | ||
| * Resolve a pending tool approval request. Called when the client sends an approval or denial | ||
| * response for a tool call that requires human-in-the-loop confirmation. | ||
| * | ||
| * @param requestId the request ID from the ApprovalRequest event | ||
| * @param approved true to approve, false to deny | ||
| * @return true if the request was found and resolved, false if not found (timed out or invalid) | ||
| */ | ||
| default boolean resolveApproval(String requestId, boolean approved) { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * Stop the provider itself, releasing engine-level resources shared across all sessions (e.g. | ||
| * HTTP connection pools, thread pools). Called once when the entire engine shuts down. | ||
| */ | ||
| default void stop() {} | ||
|
|
||
| static DataAgentProvider load(KyuubiConf conf) { | ||
| String providerClass = conf.get(KyuubiConf.ENGINE_DATA_AGENT_PROVIDER()); | ||
| try { | ||
| return (DataAgentProvider) | ||
| DynConstructors.builder(DataAgentProvider.class) | ||
| .impl(providerClass, KyuubiConf.class) | ||
| .impl(providerClass) | ||
| .buildChecked() | ||
| .newInstanceChecked(conf); | ||
| } catch (ClassCastException e) { | ||
| throw new IllegalArgumentException( | ||
| "Class " | ||
| + providerClass | ||
| + " is not a child of '" | ||
| + DataAgentProvider.class.getName() | ||
| + "'.", | ||
| e); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException("Error while instantiating '" + providerClass + "': ", e); | ||
| } | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
...-engine/src/main/java/org/apache/kyuubi/engine/dataagent/provider/ProviderRunRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kyuubi.engine.dataagent.provider; | ||
|
|
||
| /** | ||
| * User-facing request parameters for a provider-level agent invocation. Only contains fields from | ||
| * the caller (question, model override, etc.). Adding new per-request options does not require | ||
| * changing the {@link DataAgentProvider} interface. | ||
| */ | ||
| public class ProviderRunRequest { | ||
|
|
||
| private final String question; | ||
| private String modelName; | ||
| private String approvalMode; | ||
|
|
||
| public ProviderRunRequest(String question) { | ||
| this.question = question; | ||
| } | ||
|
|
||
| public String getQuestion() { | ||
| return question; | ||
| } | ||
|
|
||
| public String getModelName() { | ||
| return modelName; | ||
| } | ||
|
|
||
| public ProviderRunRequest modelName(String modelName) { | ||
| this.modelName = modelName; | ||
| return this; | ||
| } | ||
|
|
||
| public String getApprovalMode() { | ||
| return approvalMode; | ||
| } | ||
|
|
||
| public ProviderRunRequest approvalMode(String approvalMode) { | ||
| this.approvalMode = approvalMode; | ||
| return this; | ||
| } | ||
| } |
62 changes: 62 additions & 0 deletions
62
...t-engine/src/main/java/org/apache/kyuubi/engine/dataagent/provider/echo/EchoProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kyuubi.engine.dataagent.provider.echo; | ||
|
|
||
| import java.util.function.Consumer; | ||
| import org.apache.kyuubi.engine.dataagent.provider.DataAgentProvider; | ||
| import org.apache.kyuubi.engine.dataagent.provider.ProviderRunRequest; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.AgentEvent; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.AgentFinish; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.AgentStart; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.ContentComplete; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.ContentDelta; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.StepEnd; | ||
| import org.apache.kyuubi.engine.dataagent.runtime.event.StepStart; | ||
|
|
||
| /** A simple echo provider for testing purposes. Simulates the agent event stream. */ | ||
| public class EchoProvider implements DataAgentProvider { | ||
|
|
||
| @Override | ||
| public void open(String sessionId, String user) {} | ||
|
|
||
| @Override | ||
| public void run(String sessionId, ProviderRunRequest request, Consumer<AgentEvent> onEvent) { | ||
| String question = request.getQuestion(); | ||
|
|
||
| onEvent.accept(new AgentStart()); | ||
| onEvent.accept(new StepStart(1)); | ||
|
|
||
| // Simulate token-level streaming | ||
| String reply = | ||
| "[DataAgent Echo] I received your question: " | ||
| + question | ||
| + "\n" | ||
| + "This is the Data Agent engine in echo mode. " | ||
| + "Please configure an LLM provider (e.g., OPENAI_COMPATIBLE) for actual data analysis."; | ||
| for (String token : reply.split("(?<=\\s)")) { | ||
| onEvent.accept(new ContentDelta(token)); | ||
| } | ||
|
|
||
| onEvent.accept(new ContentComplete(reply)); | ||
| onEvent.accept(new StepEnd(1)); | ||
| onEvent.accept(new AgentFinish(1, 0, 0, 0)); | ||
| } | ||
|
|
||
| @Override | ||
| public void close(String sessionId) {} | ||
| } |
37 changes: 37 additions & 0 deletions
37
...ent-engine/src/main/java/org/apache/kyuubi/engine/dataagent/runtime/event/AgentError.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.kyuubi.engine.dataagent.runtime.event; | ||
|
|
||
| /** An error occurred during agent execution. */ | ||
| public final class AgentError extends AgentEvent { | ||
| private final String message; | ||
|
|
||
| public AgentError(String message) { | ||
| super(EventType.ERROR); | ||
| this.message = message; | ||
| } | ||
|
|
||
| public String message() { | ||
| return message; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "AgentError{message='" + message + "'}"; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.