-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
dewmal edited this page Jul 26, 2024
·
2 revisions
Here's a simple example of how to use Ceylon to create a multi-agent system for a trading decision process:
from ceylon import Agent, AgentJobStepRequest, AgentJobResponse, JobRequest, JobSteps, Step, RunnerAgent
class TechnicalAnalysisAgent(Agent):
async def execute_request(self, request: AgentJobStepRequest) -> AgentJobResponse:
return AgentJobResponse(
worker=self.details().name,
job_data={"MA": 100.0, "EMA": 200.0}
)
class NewsSentimentAgent(Agent):
async def execute_request(self, request: AgentJobStepRequest) -> AgentJobResponse:
return AgentJobResponse(
worker=self.details().name,
job_data={"sentiment": "Positive"}
)
class DecisionMakerAgent(Agent):
async def execute_request(self, request: AgentJobStepRequest) -> AgentJobResponse:
return AgentJobResponse(
worker=self.details().name,
job_data={"trade": True}
)
# Create agent instances
ta_agent = TechnicalAnalysisAgent(name="ta", role="Technical Analyst")
news_agent = NewsSentimentAgent(name="news", role="News Analyst")
decision_agent = DecisionMakerAgent(name="decision", role="Decision Maker")
# Create the runner agent
chief = RunnerAgent(workers=[ta_agent, news_agent, decision_agent])
# Define the job
job = JobRequest(
title="Trading Decision",
explanation="Analyze market data and make a trading decision",
steps=JobSteps(steps=[
Step(worker="ta", explanation="Perform technical analysis", dependencies=[]),
Step(worker="news", explanation="Analyze news sentiment", dependencies=[]),
Step(worker="decision", explanation="Make trading decision", dependencies=["ta", "news"])
])
)
# Execute the job
result = chief.execute(job)
print(result)
This example demonstrates how to:
- Define custom agents for different tasks
- Create a runner agent to orchestrate the process
- Define a job with multiple steps and dependencies
- Execute the job and get the result
Explore more practical examples and Colab scripts to understand the versatility of Ceylon:
- News Writing Panel: Colab Script
- Meeting Scheduler: Colab Script
- Single Item Auction: Colab Script
These examples showcase different applications of Ceylon, helping you understand how to leverage its capabilities for your projects.