AG2
, simply run the following command:
autogen
or ag2
, all you need to do is upgrade it using:autogen
and ag2
are aliases for the same PyPI package.autogen.tools.dependency_injection
module. This module provides key components for dependency injection:
BaseContext
: abstract base class used to define and encapsulate data contexts, such as user account information, which can then be injected into functions or agents securely.Depends
: a function used to declare and inject dependencies, either from a context (like BaseContext
) or a function, ensuring sensitive data is provided securely without direct exposure.BaseContext
class for accounts. This will act as the base structure for dependency injection. By using this approach, sensitive information like usernames and passwords is never exposed to the LLM.
Account
instance into a function automatically.
LLMConfig
defines the LLM configurations, including the model and API key.UserProxyAgent
simulates user inputs without requiring actual human interaction (set to NEVER
).AssistantAgent
represents the AI agent, configured with the LLM settings.bob
is injected as a dependency.
Note: You can also use account: Account = Depends(bob_account)
as an alternative syntax.
BaseContext
. Here’s how to inject simple parameters directly.
LLMConfig
defines the LLM configurations, including the model and API key.UserProxyAgent
simulates user inputs without requiring actual human interaction (set to NEVER
).AssistantAgent
represents the AI agent, configured with the LLM settings.Account
, you can directly inject individual parameters, such as the username and password, into a function. This allows for more granular control over the data injected into the function, and still ensures that sensitive information is managed securely.
Here’s how you can set it up:
alice_account
, while another can use bob_account
.
GroupChat
with two assistant agents.
assistant_1
, we inject the alice_account
context using Depends(alice_account)
, ensuring that it retrieves the balance for Alice’s account.assistant_2
, we inject the bob_account
context using Depends(bob_account)
, ensuring that it retrieves the balance for Bob’s account.