async def BrowserUse__browser_agent(task: str, expected_output: str):
    """An AI agent that can browse the web, extract information, and perform actions."""
    from browser_use import Agent
    
    # Get or create the browser instance
    browser = await BrowserManager.initialize()
    
    # Create a new context for this agent run
    context = await BrowserManager.get_context()
    
    # Create the agent with the browser context
    agent = Agent(
        task=task+"\n\nExpected Output: "+expected_output,
        llm=get_llm(),
        browser=browser,
        browser_context=context,  # Use persistent context
        generate_gif=False
    )
    
    try:
        result = await agent.run()
        return result.final_result()
    finally:
        # Clean up the context after the agent is done
        if context:
            await context.close()
An AI agent that can browse the web, extract information, and perform actions.
src/upsonic/server/level_utilized/bu/browseruse.py