def _init_agent()

in devai-api/app/gitlab_utils.py [0:0]


def _init_agent(new_gitlab_branch: str):
    """Initializes an agent with the GitLab toolkit.

    Args:
        new_gitlab_branch (str): The name of the branch to use for the agent.

    Returns:
        Agent: The initialized agent.
    """
    gitlab = GitLabAPIWrapper(gitlab_branch=new_gitlab_branch)
    toolkit = GitLabToolkit.from_gitlab_api_wrapper(gitlab)

    with telemetry.tool_context_manager(USER_AGENT):
        llm = ChatVertexAI(model_name=MODEL_NAME,
            convert_system_message_to_human=True,
            temperature=0.2,
            max_output_tokens=8192)

    agent = initialize_agent(
        toolkit.get_tools(), 
        llm, 
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, 
        verbose=True,
        handle_parsing_errors=True,
        max_iterations=10,
        return_intermediate_steps=True,
        early_stopping_method="generate",
    )

    return agent