Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activate deactivate agents #4800

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

peterychang
Copy link
Collaborator

Why are these changes needed?

Create startup/shutdown functions

Related issue number

#4705

Checks

@peterychang
Copy link
Collaborator Author

Getting this up for review. I'll see if any other agents need something done and add documentation for this after the holidays

@jackgerrits
Copy link
Member

Let's keep it to deactivation initially since there is currently no clear use case for activation but there is for deactivation

@jackgerrits
Copy link
Member

Also matter of preference, but I would prefer close

@@ -532,6 +542,13 @@ async def stop(self) -> None:
"""Stop the runtime message processing loop."""
if self._run_context is None:
raise RuntimeError("Runtime is not started")

# deactivate all the agents that have been activated
for agent_id in self._activated_agents:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering we just want shutdown, would be easier to just iterate _instantiated_agents here instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instantiated agents aren't necessarily activated. I was worried there would be code that could break in deactivate if it weren't set up in activate (I saw these functions as pairs)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my point - I don't think we want to introduce two phase initialization here without a clear reason.

I dont view it as a pair because deactivate is more like a destructor

@husseinmozannar
Copy link
Contributor

reminder to also update autogen studio code where close is called or create an issue so that victor updates it later

@peterychang
Copy link
Collaborator Author

Let's keep it to deactivation initially since there is currently no clear use case for activation but there is for deactivation

Is there a particular reason not to have the activation portion in place? The behavior for everything right now is just passing, and I could foresee situations where you want a separate initialization component outside the constructor

@jackgerrits
Copy link
Member

Let's keep it to deactivation initially since there is currently no clear use case for activation but there is for deactivation

Is there a particular reason not to have the activation portion in place? The behavior for everything right now is just passing, and I could foresee situations where you want a separate initialization component outside the constructor

Initialization should happen in the agent's factory so the functionality is already provided and then just adds a different way to achieve the same thing without a clear use case.

@peterychang
Copy link
Collaborator Author

Let's keep it to deactivation initially since there is currently no clear use case for activation but there is for deactivation

Is there a particular reason not to have the activation portion in place? The behavior for everything right now is just passing, and I could foresee situations where you want a separate initialization component outside the constructor

Initialization should happen in the agent's factory so the functionality is already provided and then just adds a different way to achieve the same thing without a clear use case.

Ok. The task described activation as lazily being called on the first message to the agent. In that case, I'll just remove the activation portion and assume its part of the factory

@jackgerrits
Copy link
Member

Let's keep it to deactivation initially since there is currently no clear use case for activation but there is for deactivation

Is there a particular reason not to have the activation portion in place? The behavior for everything right now is just passing, and I could foresee situations where you want a separate initialization component outside the constructor

Initialization should happen in the agent's factory so the functionality is already provided and then just adds a different way to achieve the same thing without a clear use case.

Ok. The task described activation as lazily being called on the first message to the agent. In that case, I'll just remove the activation portion and assume its part of the factory

Yep, let's assume instantiation==activation. Then deactivation is just destruction. Less book keeping and simpler

Comment on lines 582 to 585
# close all the agents that have been instantiated
for agent_id in self._instantiated_agents:
agent = await self._get_agent(agent_id)
await agent.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ekzhu what are your thoughts on this? I often see stop() and start() run multiple times in a sequence, this effectively breaks this.

@peterychang it might be better add close to SingleThreadedAgentRuntime and just do it on demand there?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a little redundant to have to call close() before stop() every time you want to stop the runtime. It also doesn't really take care of the `stop_when_idle' case, since shutdown will occur outside of the caller's control.

I'll separate out the call just to clean up the duplicate code though

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have tests that start and stop the same runtime in sequence since the expectation is that you're just starting/stopping the processing loop - not killing the agents themselves.

async def test_message_handler_router() -> None:

These tests also call try_get_underlying_agent_instance after calling stop, so the expectation is the agents arent dead yet.

I think for this reason we would want stop and close to be distinct calls. The runtime can become a context manager then people don't really need to think about closing and makes it more idiomatic. Close can also call stop if it hasn't been called already as a nicety

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants