Closed iplayfast closed 7 months ago
Works here when i remove the comma at the end: MainTask = """Write the snake game in python""",
@Toon-nooT Thanks for that, I didn't see the comma. I'm trying to get the coder to write code, the critic to criticise it, and the coder to update based on the criticism. Here is some sample code. The problem is that The original code is lost. I've been trying various things, suggestions welcome.
import os
from crewai import Agent, Task, Crew, Process
from langchain.llms import Ollama
#os.environ["OPENAI_API_KEY"] = "Your Key"
ollama = Ollama(model="mistral")
# Define your tools, custom or not.
# Install duckduckgo-search for this example:
#
# !pip install -U duckduckgo-search
from langchain.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()
# Define your agents with roles and goals
coder = Agent(
role='Senior Software Engineer',
goal='Create software as needed',
backstory="""You are a Senior Software Engineer at a leading tech think tank.
Your expertise in programming in python or c++.""",
verbose=True,
allow_delegation=False,
#tools=[search_tool],
# llm=OpenAI(temperature=0.7, model_name="gpt-4"). It uses langchain.chat_models, default is GPT4
llm = ollama
)
critic = Agent(
role='Software analyist',
goal='create prefect code, by analizing the code that is given for errors',
backstory="""You are a software engineer that specializes in checking code
for errors. You have an eye for detail and a knack for finding hidden bugs.
You check for missing imports, variable declarations and syntax errors. You also check for security vulnerabilities, and logic errors""",
verbose=True,
allow_delegation=True,
llm = ollama
)
MainTask = """Write the snake game in python """
# Create tasks for your agents
task1 = Task(
description=MainTask,
agent=coder
)
task2 = Task(
description="""using the code produced from the coder, check for errors. If no errors exist return "PASS", else return "FAIL".
and the reasons why it failed.""",
agent=critic
)
# Instantiate your crew with a sequential process
crew = Crew(
agents=[coder, critic],
tasks=[task1, task2],
verbose=2, # Crew verbose more will let you know what tasks are being worked on, you can set it to 1 or 2 to different logging levels
process=Process.sequential # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
)
# Get your crew to work!
result = crew.kickoff()
while "PASS" not in result:
taskfix = Task(description = (MainTask+result),agent=coder)
crew=Crew(agents=[coder,critic],tasks=[taskfix,task2],verbose=2,process=Process.sequential)
task1.description = MainTask + result
result = crew.kickoff()
print("######################")
print(result)
Afaik, the result returned, is only the result from the last task. So it makes sense that no code is returned. The result of the crew.kickoff should be able to be parsed per agent or so, but that will only come in a future version
gives an error from pydantic about description must be a str. You also cannot update a task description after your crew has run. (when you are doing multiple runs).
also will give an error.
It doesn't make sense that a task is static and cannot be updated to reflect new information that comes in.
Is there a way to update a description?