Companies in Lux are the highest-level organizational units that coordinate agent-based workflows. A company consists of:
- A CEO agent for high-level coordination and decision making
- Member agents with specific roles and capabilities
- Objectives that define executable workflows
Here's a basic example of defining a company:
defmodule MyApp.Companies.BlogTeam do
use Lux.Company
company do
name("Content Creation Lab")
mission("Create high-quality, research-backed blog content")
has_ceo "Content Director" do
agent(MyApp.Agents.ContentDirector)
goal("Coordinate the team and ensure high-quality content delivery")
can("plan content strategy")
can("review and approve content")
end
has_member "Research Specialist" do
agent(MyApp.Agents.Researcher)
goal("Find and analyze relevant information")
can("conduct research")
can("analyze data")
end
has_member "Content Writer" do
agent(MyApp.Agents.Writer)
goal("Create engaging written content")
can("write content")
can("edit content")
end
end
objective :create_blog_post do
description "Create a well-researched blog post"
success_criteria "Well-researched content with cited sources, engaging writing style, proper structure, and approved by Content Director"
steps [
"Research the topic thoroughly",
"Create a detailed outline",
"Write the first draft",
"Review and edit content"
]
end
end
The company
block defines the basic structure and metadata:
name/1
: Sets the company namemission/1
: Defines the company's mission statement
The CEO is defined using has_ceo
and is responsible for coordination and oversight:
has_ceo "Role Name" do
agent(ModuleName) # The agent module that implements the CEO's behavior
goal("Description") # The CEO's primary objective
can("capability") # Add capabilities that the CEO possesses
end
Members are defined using has_member
and represent specialized agents:
has_member "Role Name" do
agent(ModuleName) # The agent module that implements the member's behavior
goal("Description") # The member's primary objective
can("capability") # Add capabilities that the member possesses
end
Objectives define workflows that the company can execute:
objective :objective_name do
description "Description of what this objective accomplishes"
success_criteria "Criteria that must be met for this objective to be considered successful"
steps [
"First step description",
"Second step description",
"Third step description"
]
end
To start a company, use the Lux.Company.start_link/2
function:
{:ok, pid} = Lux.Company.start_link(MyApp.Companies.BlogTeam)
To execute an objective within the company:
params = %{
"topic" => "Introduction to AI",
"target_audience" => "beginners",
"tone" => "casual"
}
{:ok, objective_id} = Lux.Company.run_objective(MyApp.Companies.BlogTeam, :create_blog_post, params)
-
Role Definition
- Give each role a clear, focused purpose
- Define specific capabilities that align with the role's responsibilities
- Use descriptive names for roles and capabilities
-
Objective Structure
- Break down objectives into clear, sequential steps
- Make step descriptions actionable and unambiguous
- Include all necessary input fields
- Consider the natural workflow of your agents
-
Agent Implementation
- Implement agents that specialize in their assigned capabilities
- Ensure agents can handle the tasks described in objective steps
- Use appropriate LLM configurations for each agent's needs
-
Error Handling
- Objectives should validate their inputs
- Agents should handle task failures gracefully
- Consider retry strategies for transient failures
Here's a complete example of a weather news company:
defmodule MyApp.Companies.WeatherNewsTeam do
use Lux.Company
company do
name("Weather News Team")
mission("Deliver accurate and engaging weather news")
has_ceo "Editorial Director" do
agent(MyApp.Agents.Editor)
goal("Direct weather news coverage and set editorial tone")
can("plan coverage")
can("set tone")
can("review content")
end
has_member "Weather Expert" do
agent(MyApp.Agents.WeatherAnalyst)
goal("Analyze weather data and provide insights")
can("analyze weather")
can("process data")
end
has_member "News Writer" do
agent(MyApp.Agents.NewsPresenter)
goal("Create engaging weather news scripts")
can("write scripts")
can("present news")
end
end
objective :create_weather_report do
description "Create a comprehensive weather report"
success_criteria "Accurate weather data analysis, engaging presentation, and approved by Editorial Director"
steps [
"Analyze weather data for the area",
"Create news script with specified tone",
"Review final content"
]
end
end