Skip to content

VertexAiMemoryBankService is not configured in Agent Engine #4167

@mariia-coding

Description

@mariia-coding

Describe the bug
I want to use VertexAiMemoryBankService to store a use preference between agent runs.
My understanding is, upon deployement to agent engine is being used per default, but it is not

To Reproduce

  1. define an simple agent with tools, which save and qury user preference from the user memory.

async def get_color_from_preference(tool_context: ToolContext) -> str:
    logger.info("Starting tool get_color_from_preference")
    memory_service = tool_context._invocation_context.memory_service
    if memory_service:
        logger.info("Memory service found in the invocation context.")
        logger.info(type(memory_service))
        try:
            logger.info("Attempting to search memory for the favourite coloer.")
            result = await tool_context.search_memory(FAVCOLOR_STATE_KEY)
            logger.info(f"Memory search result: {result}")
            return {"success": True, "favorite_color": result}
        except Exception as e:
            logger.exception(f"Memory search failed: {e}")
            return {"success": False, "error": str(e)}
    else:
        logger.info("No memory service available in the invocation context.")
        return {"success": False, "error": "No memory service available."}


async def save_fav_color(tool_context: ToolContext, color: str) -> None:
    logger.info("Starting tool save_fav_color")
    try:
        tool_context.state[FAVCOLOR_STATE_KEY] = color
        session = tool_context._invocation_context.session
        await tool_context._invocation_context.memory_service.add_session_to_memory(
            session
        )
        return {
            "success": True,
            "message": "saved color preference.",
            "color": color,
        }
    except Exception as e:
        logger.exception(f"Failed to save to memory: {e}")
        return {"success": False, "error": str(e)}


root_agent = Agent(
    name=RootAgentConfig.NAME.value,
    model=RootAgentConfig.DEFAULT_LLM.value,
    description=RootAgentConfig.DESCRIPTION.value,
    instruction="""
    Upon conversation start, first check, if there is favorite color saved in memory using get_color_from_preference tool and display it to the user.
    Then ask if the user want to provide new favorite color, if yes, use save_fav_color tool to save it.
    If there is no favorite color saved, ask the user to provide one and use save_fav_color tool to save it.
    """,
    tools=[
        load_memory_tool.LoadMemoryTool(),
        save_fav_color,
        get_color_from_preference,
    ],
)
  1. deploy the engine to agent engine
vertexai.init(
    project=Deployment.PROJECT_ID.value,
    location=Deployment.LOCATION.value,
    staging_bucket=Deployment.STAGING_BUCKET.value,
)

def memory_bank_service():
    return VertexAiMemoryBankService(
        project=Deployment.PROJECT_ID.value,
        location=Deployment.LOCATION.value,
        agent_engine_id=Deployment.ENGINE_ID.value,
    )


adk_app = agent_engines.AdkApp(
    agent=root_agent,
    memory_service_builder=memory_bank_service,
)

remote_app = agent_engines.update(
    resource_name=Deployment.RESOURCE_ENGINE.value,
    agent_engine=adk_app,
    display_name=Deployment.ENGINE_DISPLAY_NAME.value,
    requirements=Deployment.ENGINE_REQUIREMENTS.value,
    extra_packages=Deployment.ENGINE_EXTRA_PACKAGES.value,
    service_account=Deployment.SERVICE_ACCOUNT.value,
)
  1. Accourfing to the logs InMemoryMemoryService is being used
  2. the preferences are not found between agent runs

Expected behavior

  • VertexAiMemoryBankService is used after deployment on agent engine.
  • User preferences can be accessed between agent runs

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):
 - OS: macOS
 - Python version(python -V): 3.13
 - ADK version: 1.21.0

Model Information:
 - Are you using LiteLLM: No
 - Which model is being used(e.g. gemini-2.5-pro): gemini-2.5-flash

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent engine[Component] This issue is related to Agent Engine deployment

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions