Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
'Refactored by Sourcery'
  • Loading branch information
Sourcery AI committed Dec 31, 2023
commit 12653b224c78eb88067ec140d86a34300c788025
9 changes: 3 additions & 6 deletions crewai/agents/output_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
regex = (
r"Action\s*\d*\s*:[\s]*(.*?)[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)"
)
action_match = re.search(regex, text, re.DOTALL)
if action_match:
if action_match := re.search(regex, text, re.DOTALL):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CrewAgentOutputParser.parse refactored with the following changes:

if includes_answer:
raise OutputParserException(
f"{FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE}: {text}"
Expand All @@ -63,8 +62,7 @@ def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
tool_input = action_input.strip(" ")
tool_input = tool_input.strip('"')

last_tool_usage = self.tools_handler.last_used_tool
if last_tool_usage:
if last_tool_usage := self.tools_handler.last_used_tool:
usage = {
"tool": action,
"input": tool_input,
Expand All @@ -74,8 +72,7 @@ def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
f"""\nI just used the {action} tool with input {tool_input}. So I already knwo the result of that."""
)

result = self.cache.read(action, tool_input)
if result:
if result := self.cache.read(action, tool_input):
return AgentFinish({"output": result}, text)

return super().parse(text)
4 changes: 1 addition & 3 deletions crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ def _deny_user_set_id(cls, v: Optional[UUID4]) -> None:
@classmethod
@field_validator("config", mode="before")
def check_config_type(cls, v: Union[Json, Dict[str, Any]]):
if isinstance(v, Json):
return json.loads(v)
return v
return json.loads(v) if isinstance(v, Json) else v
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Crew.check_config_type refactored with the following changes:


@model_validator(mode="after")
def check_config(self):
Expand Down
5 changes: 2 additions & 3 deletions crewai/tools/agent_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,8 @@ def __execute(self, command):
if available_agent.role == agent
]

if len(agent) == 0:
if not agent:
return f"\nError executing tool. Co-worker mentioned on the Action Input not found, it must to be one of the following options: {', '.join([agent.role for agent in self.agents])}."

agent = agent[0]
result = agent.execute_task(task, information)
return result
return agent.execute_task(task, information)
Comment on lines -67 to +71
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AgentTools.__execute refactored with the following changes: