Worker
This document covers the worker
and job
execution system that manages agent
processes, handles backend registration, and coordinates job assignment and execution. This system provides the foundation for running VideoSDK agents either locally or as part of a distributed backend infrastructure.
Architecture Overview
The worker
and job
system consists of three primary components that work together to execute agent code:
- WorkerJob: The main entry point that configures and starts agent execution
- Worker: Manages process pools, backend communication, and job lifecycle
- JobContext: Provides runtime context and resources to agent entrypoint functions
Core Components
Worker Class
The Worker
class manages the complete lifecycle of agent execution, including process management, backend communication, and job coordination.
Core Responsibilities:
- Process pool management and lifecycle
- Backend registry communication
- Job assignment and execution coordination
- Resource monitoring and cleanup
- Error handling and recovery
WorkerJob
The WorkerJob
class serves as the primary entry point for creating and running agents. It accepts an entrypoint function
and configuration options
, then delegates to the Worker class for execution.
from videosdk.agents import WorkerJob, Options, JobContext, RoomOptions
# Configure worker options
options = Options(
agent_id="MyAgent",
max_processes=5,
register=True, # Registers worker with backend for job scheduling
)
# Set up room configuration
room_options = RoomOptions(
name="My Agent",
)
# Create job context
job_context = JobContext(room_options=room_options)
# Define your agent entrypoint
async def your_agent_function(ctx: JobContext):
# Your agent logic here
await ctx.connect()
# Agent implementation...
# Create and start the worker job
job = WorkerJob(
entrypoint=your_agent_function,
jobctx=lambda: job_context,
options=options,
)
job.start()
-
Entrypoint: An async function that serves as your agent's main execution logic. This function receives a
JobContext
parameter and contains your agent implementation. -
JobContext: Provides the runtime environment for your agent, managing room connections and VideoSDK integration. It handles room setup, authentication, and cleanup operations.
-
Options: Configuration settings for worker execution including process management, authentication, and backend registration. You can find worker options here ↗.
Key Methods:
start()
: Initiates worker execution based on configuration
Deployments
Choose how to deploy your VideoSDK agents based on your infrastructure needs and requirements.
Agent Cloud
Deploy your agents to VideoSDK's managed cloud infrastructure
Self Hosting with Worker
Learn how to deploy workers for self-hosted agent infrastructure
Examples - Try out yourself
We have examples to get you started. Go ahead, try out, talk to agent, understand and customize according to your needs.
Got a Question? Ask us on discord