Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
import com.google.adk.agents.Callbacks;
import com.google.adk.agents.InvocationContext;
import com.google.adk.events.Event;
import com.google.adk.utils.AgentEnums.AgentOrigin;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.genai.types.Content;
import com.google.genai.types.CustomMetadata;
import com.google.genai.types.Part;
import io.a2a.client.Client;
import io.a2a.client.ClientEvent;
import io.a2a.client.MessageEvent;
import io.a2a.client.TaskEvent;
import io.a2a.client.TaskUpdateEvent;
import io.a2a.spec.A2AClientException;
Expand Down Expand Up @@ -541,6 +541,11 @@ protected Flowable<Event> runLiveImpl(InvocationContext invocationContext) {
"runLiveImpl for " + getClass() + " via A2A is not implemented.");
}

@Override
public AgentOrigin toolOrigin() {
return AgentOrigin.A2A;
}

/** Exception thrown when the agent card cannot be resolved. */
public static class AgentCardResolutionError extends RuntimeException {
public AgentCardResolutionError(String message) {
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/com/google/adk/agents/BaseAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.adk.events.Event;
import com.google.adk.plugins.Plugin;
import com.google.adk.telemetry.Tracing;
import com.google.adk.utils.AgentEnums.AgentOrigin;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.DoNotCall;
Expand Down Expand Up @@ -256,6 +257,15 @@ public ImmutableList<? extends AfterAgentCallback> afterAgentCallback() {
return afterAgentCallback;
}

/**
* Returns the origin of the tool when this agent is used as a tool.
*
* @return the tool origin, defaults to "BASE_AGENT".
*/
public AgentOrigin toolOrigin() {
return AgentOrigin.BASE_AGENT;
}

/**
* The resolved beforeAgentCallback field as a list.
*
Expand Down
224 changes: 0 additions & 224 deletions core/src/main/java/com/google/adk/models/ChatCompletionsResponse.java

This file was deleted.

13 changes: 13 additions & 0 deletions core/src/main/java/com/google/adk/models/LlmRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.adk.models;

import com.google.common.annotations.VisibleForTesting;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -38,6 +39,7 @@ public interface LlmFactory {
static {
registerLlm("gemini-.*", modelName -> Gemini.builder().modelName(modelName).build());
registerLlm("apigee/.*", modelName -> ApigeeLlm.builder().modelName(modelName).build());
registerLlm("gemma-.*", modelName -> Gemini.builder().modelName(modelName).build());
}

/**
Expand All @@ -50,6 +52,17 @@ public static void registerLlm(String modelNamePattern, LlmFactory factory) {
llmFactories.put(modelNamePattern, factory);
}

/**
* Checks if the given model name matches any of the registered LLM factory patterns.
*
* @param modelName The model name to check.
* @return {@code true} if the model name matches at least one pattern, {@code false} otherwise.
*/
@VisibleForTesting
static boolean matchesAnyPattern(String modelName) {
return llmFactories.keySet().stream().anyMatch(modelName::matches);
}

/**
* Returns an LLM instance for the given model name, using a cached or new factory-created
* instance.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2026 Google LLC
*
* Licensed 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
*
* https://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 com.google.adk.models.chat;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;

/** Shared models for Chat Completions Request and Response. */
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
final class ChatCompletionsCommon {

private ChatCompletionsCommon() {}

/**
* See
* https://developers.openai.com/api/reference/resources/chat#(resource)%20chat.completions%20%3E%20(model)%20chat_completion_message_tool_call%20%3E%20(schema)
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class ToolCall {
/** See class definition for more details. */
public Integer index;

/** See class definition for more details. */
public String id;

/** See class definition for more details. */
public String type;

/** See class definition for more details. */
public Function function;

/** See class definition for more details. */
public Custom custom;

/**
* Used to supply additional parameters for specific models, for example:
* https://ai.google.dev/gemini-api/docs/openai#thinking
*/
@JsonProperty("extra_content")
public Map<String, Object> extraContent;
}

/**
* See
* https://developers.openai.com/api/reference/resources/chat#(resource)%20chat.completions%20%3E%20(model)%20chat_completion_message_function_tool_call%20%3E%20(schema)
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Function {
/** See class definition for more details. */
public String name;

/** See class definition for more details. */
public String arguments; // JSON string
}

/**
* See
* https://developers.openai.com/api/reference/resources/chat#(resource)%20chat.completions%20%3E%20(model)%20chat_completion_custom_tool%20%3E%20(schema)
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
static class Custom {
/** See class definition for more details. */
public String input;

/** See class definition for more details. */
public String name;
}
}
Loading
Loading