Skip to main content


Whether you're a creator dreaming up new simulated worlds, or a developer looking to enhance the GenWorlds framework and tools, our quickstart guides have got you covered.


GenWorlds utilizes GPT models, which are currently accessible through

Quickstart: Dive into GenWorlds​

Welcome! Get ready to create your first multi-agent system with GenWorlds. Let’s start:

Step 1: Install GenWorlds​

pip install genworlds

To understand the GenWorlds framework, it's crucial to understand the primitives that underpin it, you can find a simple overview here.

Step 2: Create Your First World​

Generate your initial world (by now empty), where agents and objects will live.

from import BaseWorld

# Define the World
hello_world = BaseWorld(
name="Hello World",
description="A world for testing the library.",

# Launch the World
INFO:numexpr.utils:NumExpr defaulting to 8 threads.
INFO: Started server process [25828]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on (Press CTRL+C to quit)
INFO: ('', 64237) - "WebSocket /ws" [accepted]
INFO: connection open
INFO:websocket:Websocket connected
[4816cdfb-74ab-42a4-9c2e-7d82c55c8886 Thread] Connected to world socket server ws://
INFO:4816cdfb-74ab-42a4-9c2e-7d82c55c8886 Thread:Connected to world socket server ws://

Step 3: Add Agents​

Insert one agent (a basic assistant) into your world and define their characteristics and abilities. This basic assistant is an autonomous AI Agent.

from genworlds.agents.concrete.basic_assistant.utils import generate_basic_assistant
from genworlds.worlds.concrete.base.actions import UserSpeaksWithAgentEvent

description = """Agent that helps the user to answer questions."""

# Generate a basic assistant (you have to provide the openai_api_key)
agent1 = generate_basic_assistant(

# Add wakeup events to the agents so you can interact with the agent after is sleeping

## Attach the agent to the World
INFO:     ('', 64255) - "WebSocket /ws" [accepted]
INFO: connection open
INFO:websocket:Websocket connected
[agent1 Thread] Connected to world socket server ws://
INFO:agent1 Thread:Connected to world socket server ws://

> Finished chain.
{"event_type": "agent_wants_to_sleep", "description": "The agent wants to sleep. He has to wait for new events. The sender and the target ID is the agent's ID.", "summary": "Agent1 is waiting for a new question from the user.", "created_at": "2022-01-01T00:00:00+00:00", "sender_id": "agent1", "target_id": "agent1"}
Agent goes to sleep...
{"event_type": "agent_goes_to_sleep", "description": "The agent goes to sleep.", "summary": null, "created_at": "2023-10-03T15:03:45.741527", "sender_id": "agent1", "target_id": null}

Here you will see a long output till the agents go to sleep.

If you use .env files to store your openai_api_key, you can load it with:

import os
from dotenv import load_dotenv
openai_api_key = os.environ.get("OPENAI_API_KEY")

Step 4: Specify Actions and Events of an Object​

The most important step to define world entities, or objects more in particular is defining its actions. The actions are the functions that can be triggered through the socket usually by agents. So, when an agent triggers an action, the action will perform some logic and will send an event to the socket. The event will be received by the agent that triggered the action and by the other agents that are subscribed to it.

from import AbstractEvent
from import AbstractAction
from genworlds.objects.abstracts.object import AbstractObject

# Create two events and one action
# Event that the agent will use to ask for the sum of two numbers
class AgentWantsToAddTwoNumbers(AbstractEvent):
event_type = "agent_wants_to_add_two_numbers_event"
description = "Sends two float numbers to be added in a deterministic way."
number1 : float
number2 : float

# Event that the SimpleCalculator will send to the agent with the sum of the two numbers
class SendAddedNumbersToAgent(AbstractEvent):
event_type = "send_added_numbers_to_agent_event"
description = "Sends the requested deterministic sum of the two numbers to the agent"
sum : float

# The action that will be triggered by the event and will perform the addition of the two numbers
class AddTwoNumbers(AbstractAction):
trigger_event_class = AgentWantsToAddTwoNumbers
description = "Is used to add two float numbers in a deterministic way."

def __init__(self, host_object: AbstractObject):
self.host_object = host_object

def __call__(self, event:AgentWantsToAddTwoNumbers):
event = SendAddedNumbersToAgent(,
sum = event.number1 + event.number2,

We all can agree that is a bit boilerplate for just adding two numbers, but this syntax is very useful when you want to create more complex actions that will require more logic.

Step 5: Define the Object and attach the actions and events to it​

Now we can create a SimpleCalculator object, and add the deterministic action AddTwoNumbers to it. So when an agent triggers this action, it will be adding two numbers in a deterministic way, not using any LLM. You can see it as an OpenAI Plugin.

# Define the SimpleCalculator Class
class SimpleCalculator(AbstractObject):
def __init__(self, id:str):
actions = [AddTwoNumbers(host_object=self)]
super().__init__(name="Simple Calculator",
description="Object used to do some calculations such as adding two numbers.",

# Instantiate the SimpleCalculator Class
simple_calculator = SimpleCalculator(id="simple_calculator")

# Incorporate the simple_calculator object into the World
INFO:     ('', 64361) - "WebSocket /ws" [accepted]
INFO: connection open
INFO:websocket:Websocket connected
[simple_calculator Thread] Connected to world socket server ws://
INFO:simple_calculator Thread:Connected to world socket server ws://

Step 6: Interact with World entities​

Now we want to wake up one of the agents and send a message so it can use the SimpleCalculator object. That is probably the easiest way of interacting with an agent. First we are going to instantiate a TestUser.

from genworlds.worlds.concrete.base.actions import UserSpeaksWithAgentEvent
from genworlds.utils.test_user import TestUser

# Create a Testing User
test_user = TestUser()
INFO:     ('', 64375) - "WebSocket /ws" [accepted]
INFO: connection open
INFO:websocket:Websocket connected
[test_user Thread] Connected to world socket server ws://
INFO:test_user Thread:Connected to world socket server ws://

And now we can send a message to the agent.

message_to_send = UserSpeaksWithAgentEvent(,
message="Please add the numbers 2.45 and 6.78 and send me the result.",

# Send the message to John
{"event_type": "user_speaks_with_agent_event", "description": "The user speaks with an agent.", "summary": null, "created_at": "2023-10-03T15:34:31.224852", "sender_id": "test_user", "target_id": "agent1", "message": "Please add the numbers 2.45 and 6.78 and send me the result."}
Agent is waking up...
> Finished chain.
{"event_type": "agent_speaks_with_user_event", "description": "An agent speaks with the user.", "summary": null, "created_at": "2023-10-03T15:35:21.921470", "sender_id": "agent1", "target_id": null, "message": "The result of adding 2.45 and 6.78 is 9.23."}
> Finished chain.
Agent goes to sleep...
{"event_type": "agent_goes_to_sleep", "description": "The agent goes to sleep.", "summary": null, "created_at": "2023-10-03T15:35:39.997321", "sender_id": "agent1", "target_id": null}

Step 7: Explore More​

Now, delve into more advanced concepts with the following tutorials:

  • Simple Collaboration Method An example of a basic world, with two agents that cooperate to achieve a very simple task.

  • Foundational in-house RAG World An example of a RAG (Retrieval Augmented Generation) World that can be used as a foundational piece from where to expand and create a knowledge source of your projects. Here you will learn a lot about deterministic actions and objects.

  • Custom Q&A Agent In this tutorial, you will learn how you can create custom autonomous agents that have multiple thoughts and how they get integrated into already existing worlds.