Skip to content

Add doc samples for Agent Engine #13734

Open

Description

@yeesian

Activity

  1. madhavmadupu commented on Jan 11, 2026

    @madhavmadupu
    Contributor

    Hi @yeesian,

    I've been looking at the Agent Engine documentation and its subsections to identify the key code samples needed. I see you've already started a PR (#13735), but in case it's still in progress or needs more coverage for the Sessions and Memory Bank sections, I’ve drafted a few snippets below that align with the current SDK.

    These snippets follow the python-docs-samples format with region tags for easy documentation integration.

    1. Create an Agent Engine instance with Memory Bank config

    This sample shows how to initialize the client and create an engine specifically configured for memory generation.

    # [START agent_builder_create_agent_engine]
    import vertexai
    
    def create_agent_engine(project_id: str, location: str):
        """Creates an Agent Engine instance with Memory Bank configuration."""
        vertexai.init(project=project_id, location=location)
        client = vertexai.Client(project=project_id, location=location)
        
        # Create an engine with a specific model for memory generation
        agent_engine = client.agent_engines.create(
            config={
                "context_spec": {
                    "memory_bank_config": {
                        "generation_config": {
                            "model": f"projects/{project_id}/locations/{location}/publishers/google/models/gemini-1.5-flash"
                        }
                    }
                }
            }
        )
        print(f"Created Agent Engine: {agent_engine.api_resource.name}")
        return agent_engine
    # [END agent_builder_create_agent_engine]

    2. Generate Memories

    This snippet covers the Memory Bank subsection, allowing users to trigger memory extraction from stored sessions.

    # [START agent_builder_generate_memories]
    import vertexai
    
    def generate_memories(project_id: str, location: str, agent_engine_name: str):
        """Generates memories for a specific Agent Engine instance."""
        vertexai.init(project=project_id, location=location)
        client = vertexai.Client(project=project_id, location=location)
        
        # agent_engine_name format: 'projects/{project}/locations/{location}/reasoningEngines/{id}'
        response = client.agent_engines.memories.generate(
            name=agent_engine_name
        )
        print("Memories generated successfully.")
        return response
    # [END agent_builder_generate_memories]

    3. Delete an Agent Engine instance

    A standard cleanup snippet for the management subsection.

    # [START agent_builder_delete_agent_engine]
    import vertexai
    
    def delete_agent_engine(project_id: str, location: str, agent_engine_id: str):
        """Deletes an Agent Engine instance."""
        vertexai.init(project=project_id, location=location)
        client = vertexai.Client(project=project_id, location=location)
        
        client.agent_engines.delete(name=agent_engine_id)
        print(f"Deleted Agent Engine: {agent_engine_id}")
    # [END agent_builder_delete_agent_engine]

    Let me know if these align with what you're planning for #13735, or if you'd like me to add snippets for specific frameworks like LangChain or ADK as mentioned in the overview!

  2. yeesian commented on Jan 12, 2026

    @yeesian
    Author

    Let me know if these align with what you're planning for #13735, or if you'd like me to add snippets for specific frameworks like LangChain or ADK as mentioned in the overview!

    I've updated the PR to be just a draft, and am happy for you to contribute snippets (based on what you have in #13734 (comment) or beyond [if you already studied the documentation]), thank you so much!

  3. madhavmadupu commented on Jan 12, 2026

    @madhavmadupu
    Contributor

    Thanks @yeesian! I'll get these snippets organized into the correct file structure with region tags and add them to the PR (or create a new one linked to it) shortly. I'll also look into adding snippets for LangChain as mentioned.

  4. madhavmadupu commented on Jan 12, 2026

    @madhavmadupu
    Contributor

    Hi @yeesian, I've implemented the samples for creating/deleting agent engines and generating memories, including region tags and unit tests. I've pushed them to my branch [link to your branch] and can open a PR or add them to #13735 if preferred.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    samplesIssues that are directly related to samples.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions