-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixing identation for AgentTools * updating gitignore to exclude quick test script * startingprompt translation * supporting individual task output * adding agent to task output * cutting new version * Updating README example
- Loading branch information
1 parent
234a2c7
commit 7954f6b
Showing
11 changed files
with
125 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ __pycache__ | |
dist/ | ||
.env | ||
assets/* | ||
.idea | ||
.idea | ||
test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,53 @@ | ||
"""Prompts for generic agent.""" | ||
|
||
from textwrap import dedent | ||
from typing import ClassVar | ||
import json | ||
import os | ||
from typing import ClassVar, Dict, Optional | ||
|
||
from langchain.prompts import PromptTemplate | ||
from pydantic import BaseModel | ||
from pydantic import BaseModel, Field, PrivateAttr, model_validator | ||
|
||
|
||
class Prompts(BaseModel): | ||
"""Prompts for generic agent.""" | ||
|
||
TASK_SLICE: ClassVar[str] = dedent( | ||
"""\ | ||
Begin! This is VERY important to you, your job depends on it! | ||
Current Task: {input}""" | ||
_prompts: Optional[Dict[str, str]] = PrivateAttr() | ||
language: Optional[str] = Field( | ||
default="en", | ||
description="Language of crewai prompts.", | ||
) | ||
|
||
SCRATCHPAD_SLICE: ClassVar[str] = "\n{agent_scratchpad}" | ||
|
||
MEMORY_SLICE: ClassVar[str] = dedent( | ||
"""\ | ||
This is the summary of your work so far: | ||
{chat_history}""" | ||
) | ||
|
||
ROLE_PLAYING_SLICE: ClassVar[str] = dedent( | ||
"""\ | ||
You are {role}. | ||
{backstory} | ||
Your personal goal is: {goal}""" | ||
) | ||
|
||
TOOLS_SLICE: ClassVar[str] = dedent( | ||
"""\ | ||
TOOLS: | ||
------ | ||
You have access to the following tools: | ||
{tools} | ||
To use a tool, please use the exact following format: | ||
@model_validator(mode="after") | ||
def load_prompts(self) -> "Prompts": | ||
"""Load prompts from file.""" | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
prompts_path = os.path.join(dir_path, f"prompts/{self.language}.json") | ||
|
||
``` | ||
Thought: Do I need to use a tool? Yes | ||
Action: the action to take, should be one of [{tool_names}], just the name. | ||
Action Input: the input to the action | ||
Observation: the result of the action | ||
``` | ||
with open(prompts_path, "r") as f: | ||
self._prompts = json.load(f)["slices"] | ||
return self | ||
|
||
When you have a response for your task, or if you do not need to use a tool, you MUST use the format: | ||
``` | ||
Thought: Do I need to use a tool? No | ||
Final Answer: [your response here] | ||
```""" | ||
) | ||
|
||
VOTING_SLICE: ClassVar[str] = dedent( | ||
"""\ | ||
You are working on a crew with your co-workers and need to decide who will execute the task. | ||
These are your format instructions: | ||
{format_instructions} | ||
These are your co-workers and their roles: | ||
{coworkers}""" | ||
) | ||
|
||
TASK_EXECUTION_WITH_MEMORY_PROMPT: ClassVar[str] = PromptTemplate.from_template( | ||
ROLE_PLAYING_SLICE + TOOLS_SLICE + MEMORY_SLICE + TASK_SLICE + SCRATCHPAD_SLICE | ||
) | ||
|
||
TASK_EXECUTION_PROMPT: ClassVar[str] = PromptTemplate.from_template( | ||
ROLE_PLAYING_SLICE + TOOLS_SLICE + TASK_SLICE + SCRATCHPAD_SLICE | ||
) | ||
SCRATCHPAD_SLICE: ClassVar[str] = "\n{agent_scratchpad}" | ||
|
||
CONSENSUNS_VOTING_PROMPT: ClassVar[str] = PromptTemplate.from_template( | ||
ROLE_PLAYING_SLICE + VOTING_SLICE + TASK_SLICE + SCRATCHPAD_SLICE | ||
) | ||
def task_execution_with_memory(self) -> str: | ||
return PromptTemplate.from_template( | ||
self._prompts["role_playing"] | ||
+ self._prompts["tools"] | ||
+ self._prompts["memory"] | ||
+ self._prompts["task"] | ||
+ self.SCRATCHPAD_SLICE | ||
) | ||
|
||
def task_execution_without_tools(self) -> str: | ||
return PromptTemplate.from_template( | ||
self._prompts["role_playing"] | ||
+ self._prompts["task"] | ||
+ self.SCRATCHPAD_SLICE | ||
) | ||
|
||
def task_execution(self) -> str: | ||
return PromptTemplate.from_template( | ||
self._prompts["role_playing"] | ||
+ self._prompts["tools"] | ||
+ self._prompts["task"] | ||
+ self.SCRATCHPAD_SLICE | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"slices": { | ||
"task": "Begin! This is VERY important to you, your job depends on it!\n\nCurrent Task: {input}", | ||
"memory": "This is the summary of your work so far:\n{chat_history}", | ||
"role_playing": "You are {role}.\n{backstory}\n\nYour personal goal is: {goal}", | ||
"tools": "TOOLS:\n------\nYou have access to the following tools:\n\n{tools}\n\nTo use a tool, please use the exact following format:\n\n```\nThought: Do I need to use a tool? Yes\nAction: the action to take, should be one of [{tool_names}], just the name.\nAction Input: the input to the action\nObservation: the result of the action\n```\n\nWhen you have a response for your task, or if you do not need to use a tool, you MUST use the format:\n\n```\nThought: Do I need to use a tool? No\nFinal Answer: [your response here]" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, Field, model_validator | ||
|
||
|
||
class TaskOutput(BaseModel): | ||
"""Class that represents the result of a task.""" | ||
|
||
description: str = Field(description="Description of the task") | ||
summary: Optional[str] = Field(description="Summary of the task", default=None) | ||
result: str = Field(description="Result of the task") | ||
|
||
@model_validator(mode="after") | ||
def set_summary(self): | ||
excerpt = " ".join(self.description.split(" ")[0:10]) | ||
self.summary = f"{excerpt}..." | ||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
[tool.poetry] | ||
name = "crewai" | ||
version = "0.1.16" | ||
version = "0.1.23" | ||
description = "Cutting-edge framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks." | ||
authors = ["Joao Moura <[email protected]>"] | ||
readme = "README.md" | ||
|
Oops, something went wrong.