First Example#
Import Council.
[ ]:
from council.chains import Chain
from council.skills import LLMSkill
from council.llm import OpenAILLM
Setup API keys in .env file (example in repository) and use it to setup the LLM (here: OpenAILLM).
[ ]:
import dotenv
import os
dotenv.load_dotenv()
print(os.getenv("OPENAI_API_KEY", None) is not None)
openai_llm = OpenAILLM.from_env()
Create your first Hello World Skill and Wrap it in a Chain.
[ ]:
prompt = "You are responding to every prompt with a short poem titled hello world"
hw_skill = LLMSkill(llm=openai_llm, system_prompt=prompt)
hw_chain = Chain(name="Hello World", description="Answers with a poem titled Hello World", runners=[hw_skill])
Create a second Skill (that responds only with Emojis).
[ ]:
prompt = "You are responding to every prompt with an emoji that best addresses the question asked or statement made"
em_skill = LLMSkill(llm=openai_llm, system_prompt=prompt)
em_chain = Chain(name="Emoji Agent", description="Responds to every prompt with an emoji that best fits the prompt",
runners=[em_skill])
Create a Controller to route prompts to chains. Here we use the straight-forward LLMController in which an LLM instance is tasked to make a routing decision.
[ ]:
from council.controllers import LLMController
controller = LLMController(chains=[hw_chain, em_chain], llm=openai_llm, response_threshold=5)
Create an Evaluator. Here, we use an LLMEvaluator in which an LLM is tasked to evaluate each response received.
[ ]:
from council.evaluators import LLMEvaluator
evaluator = LLMEvaluator(llm=openai_llm)
Finalize setup of the Hello World first Agent by combining all components created.
[ ]:
from council.filters import BasicFilter
from council.agents import Agent
agent = Agent(controller=controller, evaluator=evaluator, filter=BasicFilter())
Now, we are ready to invoke the agent.
[ ]:
result = agent.execute_from_user_message("hello world?!")
print(result.best_message.message)
[ ]:
result = agent.execute_from_user_message("Represent with emojis, council a multi-agent framework")
print(result.best_message.message)