Skip to content

Feature Request: Add --auto_create_session flag to adk api_server CLI #4274

Closed

Description

@roanny

Summary

ADK v1.23.0 added support for automatic session creation via the auto_create_session parameter in the Runner class (commit 8e69a58). However, this feature is not exposed in the adk api_server CLI, requiring frontend applications to manually create sessions before calling /run.

Current Behavior

The _create_runner method in adk_web_server.py creates the Runner without the auto_create_session parameter:

def _create_runner(self, agentic_app: App) -> Runner:
    return Runner(
        app=agentic_app,
        artifact_service=self.artifact_service,
        session_service=self.session_service,
        memory_service=self.memory_service,
        credential_service=self.credential_service,
        # auto_create_session is not passed, defaults to False
    )

This means /run returns 404 Session not found if the session doesn't exist, even though the Runner has the capability to auto-create it.

Proposed Solution

Add a --auto_create_session flag to adk api_server:

adk api_server --auto_create_session --allow_origins="https://example.com" .

This would pass auto_create_session=True to the Runner, enabling the feature that already exists in the codebase.

Use Case

Frontend applications (especially those running in restricted environments like Looker Extensions) would benefit from simplified session management. Currently, we need to:

  1. GET /sessions/{id} to check if session exists
  2. POST /sessions/{id} to create if not found
  3. POST /run to send the message

With --auto_create_session, step 1 and 2 become unnecessary, reducing latency and code complexity.

Alternatives Considered

  1. Manual session creation in frontend - Current workaround, adds complexity
  2. Custom FastAPI server - Requires maintaining a fork
  3. Environment variable - Could also work (e.g., ADK_AUTO_CREATE_SESSION=1)

Additional Context

  • ADK Version: 1.23.0
  • The auto_create_session feature works correctly when using the Runner directly in Python scripts
  • This is specifically about exposing the existing feature via the CLI

Activity

  1. added
    web[Component] This issue will be transferred to adk-web
    on Jan 26, 2026
  2. added theissue type on Jan 26, 2026
  3. hymanme commented on Jan 27, 2026

    @hymanme

    Also need in get_fast_api_app.

  4. removed their assignment
    on Jan 27, 2026
  5. added
    good first issue[Community] This issue is good for newcomers to participate
    help wanted[Community] Extra attention is needed
    on Jan 27, 2026
  6. Subhrasameerdash commented on Jan 28, 2026

    @Subhrasameerdash

    Hii @sasha-gitg I’m new to this repository and recently started contributing to open source. I saw the labeled as “good first issue” and “help wanted,” and I would love to work on it. Could you please guide me on how to get started?

  7. Zmer03 commented on Feb 2, 2026

    @Zmer03

    Hello @sasha-gitg, I am also new to open source contributions and would like to work on this feature. I can start tonight if assigned to me.

  8. self-assigned this
    on Feb 10, 2026
  9. added a commit that references this issue on Feb 11, 2026
    40c15d0
  10. wuliang229 commented on Feb 11, 2026

    @wuliang229
    Collaborator

    @Subhrasameerdash @Zmer03 This one is already solved, feel free to look for other issues, and the CONTRIBUTING.md file is a good start.

  11. Subhrasameerdash commented on Feb 12, 2026

    @Subhrasameerdash

    Sure @wuliang229 I ll check it out

  12. mynewestgitaccount commented on Feb 21, 2026

    @mynewestgitaccount

    @wuliang229 @sasha-gitg @ekimcodes The fix you merged (#4288) was incomplete and does not work.

    Please apply the following diff so the /run and /run_sse endpoints respect the auto_create_session flag:

    diff --git a/src/google/adk/cli/adk_web_server.py b/src/google/adk/cli/adk_web_server.py
    index c61f855f..014d21ff 100644
    --- a/src/google/adk/cli/adk_web_server.py
    +++ b/src/google/adk/cli/adk_web_server.py
    @@ -1558,11 +1558,12 @@ class AdkWebServer:
     
         @app.post("/run", response_model_exclude_none=True)
         async def run_agent(req: RunAgentRequest) -> list[Event]:
    -      session = await self.session_service.get_session(
    -          app_name=req.app_name, user_id=req.user_id, session_id=req.session_id
    -      )
    -      if not session:
    -        raise HTTPException(status_code=404, detail="Session not found")
    +      if not self.auto_create_session:
    +        session = await self.session_service.get_session(
    +            app_name=req.app_name, user_id=req.user_id, session_id=req.session_id
    +        )
    +        if not session:
    +          raise HTTPException(status_code=404, detail="Session not found")
           runner = await self.get_runner_async(req.app_name)
           async with Aclosing(
               runner.run_async(
    @@ -1581,11 +1582,12 @@ class AdkWebServer:
         @app.post("/run_sse")
         async def run_agent_sse(req: RunAgentRequest) -> StreamingResponse:
           # SSE endpoint
    -      session = await self.session_service.get_session(
    -          app_name=req.app_name, user_id=req.user_id, session_id=req.session_id
    -      )
    -      if not session:
    -        raise HTTPException(status_code=404, detail="Session not found")
    +      if not self.auto_create_session:
    +        session = await self.session_service.get_session(
    +            app_name=req.app_name, user_id=req.user_id, session_id=req.session_id
    +        )
    +        if not session:
    +          raise HTTPException(status_code=404, detail="Session not found")
     
           # Convert the events to properly formatted SSE
           async def event_generator():
  13. added a commit that references this issue on Feb 22, 2026
    cdccd31
  14. sasha-gitg commented on Feb 23, 2026

    @sasha-gitg
    Collaborator

    We have a fix incoming.

  15. added a commit that references this issue on Aug 11, 2026
    00ca2ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

good first issue[Community] This issue is good for newcomers to participatehelp wanted[Community] Extra attention is neededweb[Component] This issue will be transferred to adk-web

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions