Cannot pass EventsCompactionConfig parameter to get_fast_api_app #3554
-
|
Im using get_fast_api_app from google.adk.cli.fast_api to create fastapi app instance and use the exposed routes to invoke the agent. The App instance implemented internally in google.adk.cli.adk_web_server doesnt accept the EventsCompactionConfig that is used for context compression. How do i pass the same? Do i need to have my own implementation of App instance? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You are correct, Hello! I see you're looking to enable context compaction for your ADK agent. Here’s how you can achieve that. The To enable context compaction, you need to instantiate the Here is an example of how you can create an from fastapi import FastAPI
from google.adk.apps.app import App, EventsCompactionConfig
from google.adk.cli.fast_api import AdkWebServer
from google.adk.core import agent_loader
# 1. Define your root agent (assuming it's defined in your project)
# from your_project.agents import root_agent
# 2. Create the EventsCompactionConfig with your desired settings
compaction_config = EventsCompactionConfig(
compaction_interval=3,
max_retained_events=10,
compaction_llm_config=...
)
# 3. Create the ADK App with context compaction enabled
my_adk_app = App(
name='my-agent',
root_agent=root_agent, # Your root agent
events_compaction_config=compaction_config,
)
# 4. Create a custom agent loader that returns your configured app
class MyAgentLoader(agent_loader.AgentLoader):
def get_app(self) -> App:
return my_adk_app
def get_name(self) -> str:
return my_adk_app.name
# 5. Initialize the AdkWebServer with your custom loader
adk_web_server = AdkWebServer(MyAgentLoader(), None)
# 6. Get the FastAPI app instance
fastapi_app = adk_web_server.get_fast_api_app()
# You can now run this `fastapi_app` with a server like uvicorn
# For example: uvicorn your_script_name:fastapi_app --reloadThis approach gives you full control over the |
Beta Was this translation helpful? Give feedback.
Response from ADK Answering Agent (experimental, answer may be inaccurate)
TLDR: You are correct,
get_fast_api_appis a high-level utility for theadkcommand-line tools and does not directly support passingEventsCompactionConfig. To use context compaction, you should define anAppobject with your desiredEventsCompactionConfigand then create your own FastAPI server instance to serve it.Hello! I see you're looking to enable context compaction for your ADK agent. Here’s how you can achieve that.
The
get_fast_api_appfunction is a convenience wrapper used by the ADK command-line interface and is designed to simplify the process of serving agents from a directory. It does not expose adv…