-
Notifications
You must be signed in to change notification settings - Fork 36
Update LS to Support Agent Evaluations in BI #686
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
Merged
LakshanWeerasinghe
merged 28 commits into
ballerina-platform:main
from
dan-niles:bi-test-creation-updates
Feb 17, 2026
Merged
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
35e49fe
Update test creation with additional parameters for `@test:Config`
dan-niles ab063f9
Update eval creation with eval file path for data provider
dan-niles 9701631
Add support for creating reusable agents
dan-niles d021f10
Update getTestFunction flow to retrieve test:Config parameters properly
dan-niles 9b2251f
Add support for updating config fields in tests
dan-niles e531e4d
Move chat agent back to module level
dan-niles 290214b
Update tests
dan-niles b634fca
Update tests
dan-niles 883a0aa
Add check for empty string when adding groups in tests annotation
dan-niles a56e63d
Update tests for chat service
dan-niles ef283c8
Add tests for adding and updating tests with min pass rate and evalse…
dan-niles d08fc9a
Fix coderabbit suggestions
dan-niles bc7cfaa
Refactor code
dan-niles d17c8af
Remove unused imports
dan-niles 562e57c
Fix checkstyle errors
dan-niles a6e01c1
Fix failing test
dan-niles a9e5ca9
Fix PR comments suggestions
dan-niles 93fa9ac
Update agent tool search to return input parameters
dan-niles 23b0086
Add caching for agent call builder
dan-niles c20ed20
Update failing tests
dan-niles 5475b4a
Merge branch 'main' into bi-test-creation-updates
dan-niles 067738b
Update type descriptor field name in AGENT_CALL node
dan-niles 9cd89fd
Fix failing tests
dan-niles f7d9f64
Fix failing tests
dan-niles 56bb38c
Fix failing tests
dan-niles 9f28d6c
Merge branch 'main' into bi-test-creation-updates
dan-niles 8db2827
Update test function return type to error?
dan-niles e969364
Update failing tests
dan-niles 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
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
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
195 changes: 195 additions & 0 deletions
195
...r-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/node/AgentRunBuilder.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,195 @@ | ||
| /* | ||
| * Copyright (c) 2026, WSO2 LLC. (http://www.wso2.com) | ||
| * | ||
| * WSO2 LLC. 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 io.ballerina.flowmodelgenerator.core.model.node; | ||
|
|
||
| import io.ballerina.compiler.syntax.tree.SyntaxKind; | ||
| import io.ballerina.flowmodelgenerator.core.AiUtils; | ||
| import io.ballerina.flowmodelgenerator.core.model.FlowNode; | ||
| import io.ballerina.flowmodelgenerator.core.model.NodeKind; | ||
| import io.ballerina.flowmodelgenerator.core.model.Property; | ||
| import io.ballerina.flowmodelgenerator.core.model.SourceBuilder; | ||
| import io.ballerina.flowmodelgenerator.core.utils.FlowNodeUtil; | ||
| import io.ballerina.modelgenerator.commons.FunctionData; | ||
| import io.ballerina.modelgenerator.commons.ParameterData; | ||
| import org.ballerinalang.langserver.common.utils.NameUtil; | ||
| import org.eclipse.lsp4j.TextEdit; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** | ||
| * Represents a function call node. | ||
| * | ||
| * @since 1.5.1 | ||
| */ | ||
| public class AgentRunBuilder extends CallBuilder { | ||
|
|
||
| private static final String BALLERINA = "ballerina"; | ||
|
|
||
| // Agent Call Properties | ||
| public static final String QUERY = "query"; | ||
| public static final String SESSION_ID = "sessionId"; | ||
| public static final String CONTEXT = "context"; | ||
|
|
||
| public static final String LABEL = "Agent"; | ||
| public static final String DESCRIPTION = "Create or reuse an Agent."; | ||
| static final Set<String> AGENT_CALL_PARAMS_TO_SHOW = Set.of(QUERY, SESSION_ID, CONTEXT); | ||
|
|
||
| @Override | ||
| protected NodeKind getFunctionNodeKind() { | ||
| return NodeKind.AGENT_RUN; | ||
| } | ||
|
|
||
| @Override | ||
| protected FunctionData.Kind getFunctionResultKind() { | ||
| return FunctionData.Kind.FUNCTION; | ||
| } | ||
|
|
||
| @Override | ||
| public void setConcreteConstData() { | ||
| codedata().node(NodeKind.AGENT_RUN); | ||
| metadata().description(DESCRIPTION); | ||
| } | ||
|
|
||
| @Override | ||
| public void setConcreteTemplateData(TemplateContext context) { | ||
| super.setConcreteTemplateData(context); | ||
| // TODO: This is a temporary solution until we have a proper plan for handling all generic types. | ||
| makeInferredTypePropertyOptional(); | ||
| overrideVariableName(context); | ||
| } | ||
|
|
||
| private void makeInferredTypePropertyOptional() { | ||
| if (formBuilder == null) { | ||
| return; | ||
| } | ||
| Map<String, Property> props = formBuilder.build(); | ||
| for (Map.Entry<String, Property> entry : props.entrySet()) { | ||
| Property prop = entry.getValue(); | ||
| if (prop.codedata() != null && | ||
| ParameterData.Kind.PARAM_FOR_TYPE_INFER.name().equals(prop.codedata().kind())) { | ||
| props.put(entry.getKey(), AiUtils.copyAsOptionalAdvanced(prop)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void overrideVariableName(TemplateContext context) { | ||
| if (formBuilder == null) { | ||
| return; | ||
| } | ||
| Map<String, Property> props = formBuilder.build(); | ||
| Property variableProp = props.get(Property.VARIABLE_KEY); | ||
| if (variableProp == null) { | ||
| return; | ||
| } | ||
| String uniqueVarName = NameUtil.generateVariableName("string", context.getAllVisibleSymbolNames()); | ||
dan-niles marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| props.put(Property.VARIABLE_KEY, AiUtils.createUpdatedProperty(variableProp, uniqueVarName)); | ||
| } | ||
dan-niles marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private void newVariableWithInferredTypeAndDefault(SourceBuilder sourceBuilder) { | ||
| FlowNode flowNode = sourceBuilder.flowNode; | ||
| Optional<Property> optionalType = sourceBuilder.getProperty(Property.TYPE_KEY); | ||
| Optional<Property> variable = sourceBuilder.getProperty(Property.VARIABLE_KEY); | ||
|
|
||
| if (optionalType.isEmpty() || variable.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| Property type = optionalType.get(); | ||
| String typeName = type.value().toString(); | ||
|
|
||
| if (flowNode.codedata().inferredReturnType() != null) { | ||
| Optional<Property> inferredParam = flowNode.properties().values().stream() | ||
| .filter(property -> property.codedata() != null && property.codedata().kind() != null && | ||
| property.codedata().kind().equals(ParameterData.Kind.PARAM_FOR_TYPE_INFER.name())) | ||
| .findFirst(); | ||
| if (inferredParam.isPresent()) { | ||
| String returnType = flowNode.codedata().inferredReturnType(); | ||
| Object inferredValue = inferredParam.get().value(); | ||
| // Default to "string" when the inferred type value is null or empty | ||
| String inferredType = (inferredValue != null && !inferredValue.toString().isEmpty()) | ||
| ? inferredValue.toString() | ||
| : "string"; | ||
| String inferredTypeDef = inferredParam.get() | ||
| .codedata().originalName(); | ||
| typeName = returnType.replace(inferredTypeDef, inferredType); | ||
| } | ||
| } | ||
|
|
||
| sourceBuilder.token().expressionWithType(typeName, variable.get()).keyword(SyntaxKind.EQUAL_TOKEN); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<Path, List<TextEdit>> toSource(SourceBuilder sourceBuilder) { | ||
| // Use custom variable declaration with inferred type handling and default to "string" | ||
| newVariableWithInferredTypeAndDefault(sourceBuilder); | ||
|
|
||
| FlowNode agentRunNode = sourceBuilder.flowNode; | ||
| Map<Path, List<TextEdit>> allTextEdits = new HashMap<>(); | ||
|
|
||
| generateAgentCallSource(sourceBuilder, agentRunNode, allTextEdits); | ||
|
|
||
| return allTextEdits; | ||
dan-niles marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private void generateAgentCallSource(SourceBuilder sourceBuilder, FlowNode agentRunNode, | ||
| Map<Path, List<TextEdit>> allTextEdits) { | ||
| Optional<Property> connection = agentRunNode.getProperty(Property.CONNECTION_KEY); | ||
| if (connection.isEmpty()) { | ||
| throw new IllegalStateException("Agent variable must be defined for an agent call node"); | ||
| } | ||
|
|
||
| if (FlowNodeUtil.hasCheckKeyFlagSet(agentRunNode)) { | ||
| sourceBuilder.token().keyword(SyntaxKind.CHECK_KEYWORD); | ||
| } | ||
|
|
||
| Set<String> excludeKeys = getExcludeKeys(agentRunNode); | ||
| Map<Path, List<TextEdit>> callTextEdits = sourceBuilder.token() | ||
| .name(connection.get().toSourceCode()) | ||
| .keyword(BALLERINA.equals(agentRunNode.codedata().org()) ? | ||
| SyntaxKind.DOT_TOKEN : SyntaxKind.RIGHT_ARROW_TOKEN) | ||
| .name(agentRunNode.metadata().label()) | ||
| .stepOut() | ||
| .functionParameters(agentRunNode, excludeKeys) | ||
| .textEdit() | ||
| .build(); | ||
|
|
||
| callTextEdits.forEach((path, textEdits) -> | ||
| allTextEdits.merge(path, textEdits, (existing, incoming) -> { | ||
| List<TextEdit> merged = new ArrayList<>(existing); | ||
| merged.addAll(incoming); | ||
| return merged; | ||
| })); | ||
| } | ||
|
|
||
| private Set<String> getExcludeKeys(FlowNode agentRunNode) { | ||
| return agentRunNode.properties() != null | ||
| ? agentRunNode.properties().keySet().stream() | ||
| .filter(key -> !AGENT_CALL_PARAMS_TO_SHOW.contains(key)) | ||
| .collect(Collectors.toSet()) | ||
| : new HashSet<>(); | ||
| } | ||
| } | ||
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
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
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
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
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
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.