Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ public void flush() {
} else {
logger.fine("Successfully wrote " + batch.size() + " rows to BigQuery.");
}
} catch (AppendSerializationError ase) {
}
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
if (e.getCause() instanceof AppendSerializationError ase) {
logger.log(
Level.SEVERE, "Failed to write batch to BigQuery due to serialization error", ase);
Map<Integer, String> rowIndexToErrorMessage = ase.getRowIndexToErrorMessage();
Expand All @@ -161,12 +166,9 @@ public void flush() {
logger.severe(
"AppendSerializationError occurred, but no row-specific errors were provided.");
}
} else {
logger.log(Level.SEVERE, "Failed to write batch to BigQuery", e);
}
} catch (Exception e) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
logger.log(Level.SEVERE, "Failed to write batch to BigQuery", e);
} finally {
// Clear the vectors to release the memory.
root.clear();
Expand All @@ -185,7 +187,12 @@ private void populateVector(FieldVector vector, int index, Object value) {
return;
}
if (vector instanceof VarCharVector varCharVector) {
String strValue = (value instanceof JsonNode jsonNode) ? jsonNode.asText() : value.toString();
String strValue;
if (value instanceof JsonNode jsonNode) {
strValue = jsonNode.isTextual() ? jsonNode.asText() : jsonNode.toString();
} else {
strValue = value.toString();
}
varCharVector.setSafe(index, strValue.getBytes(UTF_8));
} else if (vector instanceof BigIntVector bigIntVector) {
long longValue;
Expand Down
Loading