adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Possible to start ADK web with Agent messege?

Open Allena101 opened this issue 1 year ago • 7 comments

I want the session to start with the Agent introducing itself and presenting what it can do.

However, when starting adk web I always have to provide the first prompt to get everything going. I tried returning both a user and assistant message using before agent callback but it even then it only sends the message after the user provides the first prompt.

I did set a state flag so that the "introduction message" would only be sent once , and that part works , but as I am trying to explain, I cannot get it to work so that the Agent starts the chat.

As I am understanding this now, this is mainly an issue with adk web and would be easier to control using other methods (e.g. use the agent with an endpoint)

Allena101 avatar Jul 28 '25 11:07 Allena101

+1, this would be extremely helpful

lsgordon avatar Jul 28 '25 14:07 lsgordon

This will be great help.

jaisPank avatar Aug 11 '25 17:08 jaisPank

Hi @Allena101,

Thanks for the detailed feature request! Having the agent proactively introduce itself is definitely a common UX pattern that would improve the ADK web experience.

A few questions:

  • What's your use case? Is this for a customer-facing chatbot or internal tool?
  • How critical is this feature for your project?
  • Are you currently using an endpoint workaround, or is this blocking you?

Will update you soon!

surajksharma07 avatar Oct 10 '25 12:10 surajksharma07

@Allena101 @surajksharma07

Here’s my approach that could help if you want to build your own agent and ensure that the first message is correctly added to the session events.

Step 1 — Create the session_service and runner

session_service = InMemorySessionService()
runner = Runner(
    agent=translation_agent,
    app_name=APP_NAME,
    session_service=session_service
)

session = await session_service.create_session(
    app_name=APP_NAME,
    user_id=USER_ID,
    session_id=session_id
)

Step 2 — Send an event before starting the conversation

Before talking with your agent, send an initial event that will appear first in the event list.

content = types.Content(role='model', parts=[types.Part(text="Hello There")])
invocation_context = runner._new_invocation_context(session=ses, new_message=content)

event = Event(
    invocation_id=invocation_context.invocation_id,
    author='translation_agent',
    content=content2,
)

await session_service.append_event(session, event)

When you iterate over the session events, the first event will now be the message you added manually.

hassan9khaled avatar Oct 12 '25 20:10 hassan9khaled

@hangfei Please take a look into it.

surajksharma07 avatar Oct 30 '25 17:10 surajksharma07

@Allena101 @surajksharma07

Here’s my approach that could help if you want to build your own agent and ensure that the first message is correctly added to the session events.

Step 1 — Create the session_service and runner

session_service = InMemorySessionService() runner = Runner( agent=translation_agent, app_name=APP_NAME, session_service=session_service )

session = await session_service.create_session( app_name=APP_NAME, user_id=USER_ID, session_id=session_id ) Step 2 — Send an event before starting the conversation

Before talking with your agent, send an initial event that will appear first in the event list.

content = types.Content(role='model', parts=[types.Part(text="Hello There")]) invocation_context = runner._new_invocation_context(session=ses, new_message=content)

event = Event( invocation_id=invocation_context.invocation_id, author='translation_agent', content=content2, )

await session_service.append_event(session, event) When you iterate over the session events, the first event will now be the message you added manually.

this works.

This should be owned by application logic.

closing this now. thanks.

hangfei avatar Nov 08 '25 15:11 hangfei

What if the first agent message requires inference?

I have a planning agent that is preloaded with relevant context via the agent state. I want the agent to start the conversation with a brief summary of context, and ask clarifying questions if the preloaded context is insufficient.

This can't really be done by just appending your own agent message at the start. My current solution is to programmatically trigger a faked user message just saying "hi" which triggers the agent to respond as I want (as per the agent instructions) It's not the end of the world but it doesn't feel quite as polished as I would want the agent interaction to be.

Markus-ipse avatar Nov 08 '25 16:11 Markus-ipse