def execute_task(agent_config, task: Task, debug: bool = False):
    """Execute a task with the given agent configuration."""
    import asyncio
    
    try:
        # Check if there's a running event loop
        loop = asyncio.get_running_loop()
        if loop.is_running():
            # If there's a running loop, run the coroutine in that loop
            return asyncio.run_coroutine_threadsafe(
                execute_task_async(agent_config, task, debug), 
                loop
            ).result()
    except RuntimeError:
        # No running event loop
        pass
    
    # If no running loop or exception occurred, create a new one
    return asyncio.run(execute_task_async(agent_config, task, debug))
Execute a task with the given agent configuration.
src/upsonic/client/agent_configuration/agent_configuration.py