Skip to content

AssistantAgent

fastagency.studio.models.agents.assistant.AssistantAgent #

Bases: AgentBaseModel

llm instance-attribute #

llm: llm_type_refs

name instance-attribute #

name: str

system_message class-attribute instance-attribute #

system_message: str = (
    "You are a helpful assistant. After you successfully answer all questions and there are no new questions asked after your response (e.g. there is no specific direction or question asked after you give a response), terminate the chat by outputting 'TERMINATE' (IMPORTANT: use all caps)"
)

toolbox_1 class-attribute instance-attribute #

toolbox_1: Optional[ToolboxRef] = None

toolbox_2 class-attribute instance-attribute #

toolbox_2: Optional[ToolboxRef] = None

toolbox_3 class-attribute instance-attribute #

toolbox_3: Optional[ToolboxRef] = None

create_autogen async classmethod #

create_autogen(
    model_id: UUID, user_id: UUID, **kwargs: Any
) -> tuple[AssistantAgent, list[OpenAPI]]
Source code in fastagency/studio/models/agents/assistant.py
@classmethod
async def create_autogen(
    cls, model_id: UUID, user_id: UUID, **kwargs: Any
) -> tuple[autogen.agentchat.AssistantAgent, list[OpenAPI]]:
    my_model = await cls.from_db(model_id)

    llm_model = await my_model.llm.get_data_model().from_db(my_model.llm.uuid)

    llm = await llm_model.create_autogen(my_model.llm.uuid, user_id)

    clients = await my_model.get_clients_from_toolboxes(user_id)

    agent_name = my_model.name

    if "human_input_mode" in kwargs:
        kwargs.pop("human_input_mode")

    if "system_message" in kwargs:
        system_message = kwargs["system_message"]
        kwargs.pop("system_message")
    else:
        system_message = my_model.system_message

    agent = autogen.agentchat.AssistantAgent(
        name=agent_name,
        llm_config=llm,
        system_message=system_message,
        code_execution_config=False,
        **kwargs,
    )
    return agent, clients

from_db async classmethod #

from_db(model_id: UUID) -> T
Source code in fastagency/studio/models/base.py
@classmethod
async def from_db(cls: type[T], model_id: UUID) -> T:
    my_model_dict = await DefaultDB.backend().find_model(model_id)
    my_model = cls(**my_model_dict["json_str"])

    return my_model

get_clients_from_toolboxes async #

get_clients_from_toolboxes(user_id: UUID) -> list[OpenAPI]
Source code in fastagency/studio/models/agents/base.py
async def get_clients_from_toolboxes(self, user_id: UUID) -> list[OpenAPI]:
    clients: list[OpenAPI] = []
    for i in range(3):
        toolbox_property = getattr(self, f"toolbox_{i+1}")
        if toolbox_property is None:
            continue

        toolbox_model = await toolbox_property.get_data_model().from_db(
            toolbox_property.uuid
        )
        client = await toolbox_model.create_autogen(toolbox_property.uuid, user_id)
        clients.append(client)
    return clients

get_reference_model classmethod #

get_reference_model() -> Type[ObjectReference]
Source code in fastagency/studio/models/base.py
@classmethod
def get_reference_model(cls) -> "Type[ObjectReference]":
    if cls._reference_model is None:
        raise ValueError("reference model not set")
    return cls._reference_model