Skip to content

Examples

dewmal edited this page Jul 26, 2024 · 2 revisions

Example: Trading Decision Process

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:

  1. Define custom agents for different tasks
  2. Create a runner agent to orchestrate the process
  3. Define a job with multiple steps and dependencies
  4. Execute the job and get the result

Additional Examples

Explore more practical examples and Colab scripts to understand the versatility of Ceylon:

  1. News Writing Panel: Colab Script
  2. Meeting Scheduler: Colab Script
  3. Single Item Auction: Colab Script

These examples showcase different applications of Ceylon, helping you understand how to leverage its capabilities for your projects.

Clone this wiki locally