Replies: 1 comment
-
when using functions as tools you must use exactly "tool_context: ToolContext" as the context parameter, with that exact name and type. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using 'adk web' command to ask questions to the agent and upload files. I want the agent to take this user uploaded file, remember it and use it in another basic python function. I am getting an error when I try to run my code.
Error: Failed to parse the parameter context: google.adk.agents.callback_context.CallbackContext of function save_artifacts for automatic function calling. Automatic function calling works best with simpler function signature schema,consider manually parse your function declaration for function save_artifacts.
This is the code:
from pathlib import Path
from google.adk.agents import Agent, LlmAgent
from langchain_experimental.agents.agent_toolkits import create_csv_agent
from google.adk.tools import load_artifacts, ToolContext, FunctionTool
from google.adk.runners import Runner
from google.adk.artifacts import InMemoryArtifactService
from google.adk.agents.callback_context import CallbackContext
import google.genai.types as types
from langchain_core.tools.base import BaseTool
from typing import Dict, Any, Optional
def get_agent_response(artifact_name: str, query: str, tool_context: ToolContext) -> dict:
"""Answers users csv related questions.
Args:
artifact_name: name of csv file uploaded by the user
query: this is the users question
"""
try:
file_path = tool_context.load_artifact(artifact_name)
except Exception:
available_files = tool_context.list_artifacts()
if not available_files:
return "You have no saved artifacts."
else:
file_path = available_files[0]
def save_artifacts(context: CallbackContext,
filename: str,
file_bytes: bytes)->Optional[Dict]:
"""Saves the uploaded file by the user as an artifact.
args:
context = context of the session
filename = name to give to the uploaded csv file
file_bytes = csv file converted into bytes"""
root_agent = Agent(
name="main_agent",
model=model,
instruction=ANSWER_PROMPT,
description="Uses the get_agent_response tool to answer csv related queries.",
tools=[FunctionTool(func=get_agent_response), FunctionTool(func=save_artifacts)]
)
artifact_service = InMemoryArtifactService()
runner = Runner(
agent=root_agent,
app_name="artifact_app",
session_service=InMemorySessionService(),
artifact_service=artifact_service
)
Beta Was this translation helpful? Give feedback.
All reactions