This guide explains how to manage roles and assign agents in your Lux companies.
-
CEO
- Every company has one CEO
- Responsible for evaluating and managing objectives
- Has leadership capabilities
-
Members
- Regular company members
- Have specific capabilities
- Can be assigned to objectives
-
Contractors (Future)
- Specialized external agents
- Temporary assignments
- Access to specific objectives only
To assign an agent to a role:
{:ok, _} = Lux.Company.assign_agent(company, role_id, agent)
The agent can be:
- A local module (e.g.,
MyApp.Agents.Writer
) - A remote reference (e.g.,
{"agent-123", :research_hub}
)
Each role has specific capabilities that determine what tasks they can perform:
defmodule MyApp.Companies.BlogTeam do
use Lux.Company
company do
name "Content Creation Team"
mission "Create engaging content efficiently"
has_ceo "Content Director" do
agent MyApp.Agents.ContentDirector
goal "Direct content creation and review"
can "plan"
can "review"
can "approve"
end
members do
has_role "Lead Researcher" do
agent {"researcher-123", :research_hub}
goal "Research and analyze topics"
can "research"
can "analyze"
can "summarize"
end
end
end
end
If you try to run an objective without required roles:
{:ok, objective_id} = Lux.Company.run_objective(
MyApp.Companies.BlogTeam,
:create_blog_post,
%{"topic" => "AI"}
)
# You'll receive an error message
receive do
{:objective_failed, ^objective_id, {:missing_agent, message}} ->
IO.puts "Objective failed: #{message}"
end
-
Role Definition
- Define roles with clear, focused capabilities
- Use descriptive names that reflect the role's purpose
- Document the role's goal and responsibilities
-
Agent Assignment
- Assign agents that match the role's capabilities
- Consider using remote agents for specialized tasks
- Validate agent capabilities before assignment
-
Error Handling
- Check for
:missing_agent
errors when running objectives - Provide clear feedback when agent assignment fails
- Validate role IDs before attempting agent assignment
- Check for
-
Dynamic Role Management
- Consider implementing agent selection logic
- Keep track of agent assignments
- Monitor agent health and performance
Here's a complete example of managing roles and running an objective:
# Start the company
{:ok, _pid} = Lux.Company.start_link(MyApp.Companies.BlogTeam)
# List all roles
{:ok, roles} = Lux.Company.list_roles(MyApp.Companies.BlogTeam)
[ceo, writer] = roles
# Assign agents to roles
{:ok, _} = Lux.Company.assign_agent(MyApp.Companies.BlogTeam, ceo.id, MyApp.Agents.CEO)
{:ok, _} = Lux.Company.assign_agent(MyApp.Companies.BlogTeam, writer.id, MyApp.Agents.Writer)
# Now the objective can run successfully
{:ok, objective_id} = Lux.Company.run_objective(
MyApp.Companies.BlogTeam,
:create_blog_post,
%{"topic" => "AI"}
)
# Wait for completion
receive do
{:objective_completed, ^objective_id, results} ->
IO.puts "Objective completed successfully!"
end