Skip to content

Instantly share code, notes, and snippets.

@sutyum
Created April 21, 2024 16:36
Show Gist options
  • Save sutyum/290adc26027cd5e7c5364de77288074c to your computer and use it in GitHub Desktop.
Save sutyum/290adc26027cd5e7c5364de77288074c to your computer and use it in GitHub Desktop.
Agents with Instructor and Pydantic
#agentic.py
# https://discord.com/channels/1192246288507474000/1192247523604185189/1229828123764330577
from pydantic import BaseModel, Field
from typing import List
class Agent(BaseModel):
variable: str = Field(description="snake cased variable based off the agents role")
role: str = Field(description="The role of the agent", examples=["Senior Project Manager","Lead Developer","Senior Architect"])
goal: str = Field(description="The goal the agent is trying to achieve")
backstory: str = Field(description="A brief description of your expertise")
class Task(BaseModel):
variable: str = Field(description="snake cased variable that will call the task")
description: str = Field(description="A clear, concise statement of what the task entails.")
agent: Agent = Field(description="The agent that should be assigned to the task")
class Crew(BaseModel):
agents: List[Agent] = Field(description="4 agents that help complete the users task")
tasks: List[Task]
# ---
task = input("What is the task?: ")
resp = client.chat.completions.create(
model="wizardlm2:7b-q6_K",
max_retries=2,
messages=[
{
'role': 'system',
'content': f"""
You are an expert at creating AI agents that can complete a given task.
"""
},
{
'role': 'user',
'content': f"""
current task {task}
"""
}
],
response_model=agentic.Crew
)
# ---
lead_developer=Agent(
role="Lead Developer",
goal="Design a 3D printer for Pixie Stick activation",
backstory="With extensive experience in consumer electronics and a passion for innovation, I have led development teams to create novel devices that push the boundaries of conventional technology."
)
senior_project_manager=Agent(
role="Senior Project Manager",
goal="Manage the project timeline and coordinate between all departments",
backstory="As a seasoned project manager with over a decade of experience in managing complex engineering projects, I excel at bringing diverse teams together to meet and exceed our objectives."
)
senior_architect=Agent(
role="Senior Architect",
goal="Design the structural components of the 3D printer",
backstory="I have a deep understanding of mechanical engineering principles and a proven track record in architecting robust, efficient systems. My expertise lies in turning complex ideas into practical solutions."
)
chemical_engineer=Agent(
role="Chemical Engineer",
goal="Research the chemical composition of Pixie Sticks to optimize their use in the printer",
backstory="My research and development focus has been on understanding and harnessing chemical reactions for practical applications. I am well-versed in polymer chemistry and material science."
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment