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

Bug in example for swekit #1228

Open
callmeBalloch opened this issue Jan 27, 2025 · 0 comments
Open

Bug in example for swekit #1228

callmeBalloch opened this issue Jan 27, 2025 · 0 comments

Comments

@callmeBalloch
Copy link

callmeBalloch commented Jan 27, 2025

I get the following error

composio_toolset.get_tools(
            apps=[
                App.FILETOOL,
                App.SHELLTOOL,
                App.CODE_ANALYSIS_TOOL,
            ]
        )
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/riccardoballoch/Projects/composio-agent/.venv/lib/python3.12/site-packages/composio_crewai/toolset.py", line 171, in get_tools
    self.validate_tools(apps=apps, actions=actions, tags=tags)
  File "/Users/riccardoballoch/Projects/composio-agent/.venv/lib/python3.12/site-packages/composio/tools/toolset.py", line 1122, in validate_tools
    self.workspace.check_for_missing_dependencies(
    ^^^^^^^^^^^^^^
  File "/Users/riccardoballoch/Projects/composio-agent/.venv/lib/python3.12/site-packages/composio/tools/toolset.py", line 526, in workspace
    self._workspace = WorkspaceFactory.get(id=self._workspace_id)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/riccardoballoch/Projects/composio-agent/.venv/lib/python3.12/site-packages/composio/tools/env/factory.py", line 119, in get
    if id not in cls._workspaces:
       ^^^^^^^^^^^^^^^^^^^^^^^^^

when I try to set uo locally the following benchmark:

import argparse

from agent import get_crew

from swekit.benchmark.run_evaluation import evaluate
from swekit.config.store import IssueConfig


def bench(workspace_id: str, issue_config: IssueConfig) -> str:
    """Run benchmark on the agent."""

    # Get required tools
    crew, composio_toolset = get_crew(
        repo_path=issue_config.repo_name,
        workspace_id=workspace_id,
    )

    # Set the workspace for the tools to run.
    composio_toolset.set_workspace_id(workspace_id)

    # kick off the crew on the issue.
    return crew.kickoff(
        inputs={
            "repo": issue_config.repo_name,
            "issue": issue_config.issue_desc,
        }
    )


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Run benchmark on the agent.",
    )
    group = parser.add_mutually_exclusive_group()
    group.add_argument(
        "--test-split",
        type=str,
        default="1:2",
        help="Test split ratio (e.g. 1:2, 1:500) Maximum 500 tests per project.",
    )
    group.add_argument(
        "--test-instance-ids",
        type=str,
        default="",
        help="Test instance ids (comma-separated)",
    )
    args = parser.parse_args()

    if args.test_instance_ids:
        test_instance_ids_list = [
            id.strip() for id in args.test_instance_ids.split(",")
        ]
        test_range = "1:500"
    else:
        test_instance_ids_list = []
        test_range = args.test_split

    evaluate(
        bench,
        dry_run=False,
        test_range=test_range,
        test_instance_ids=test_instance_ids_list,
        image_name="composio/composio:latest", # if you are doing local dev
    )

Agent code:

"""CrewAI SWE Agent"""

import os
from enum import Enum
from crewai import LLM
import dotenv
import typing as t
from crewai import Agent, Crew, Process, Task
from langchain_openai import ChatOpenAI
from langchain_huggingface import ChatHuggingFace, HuggingFacePipeline
from prompts import BACKSTORY, DESCRIPTION, EXPECTED_OUTPUT, GOAL, ROLE

from composio_crewai import Action, App, ComposioToolSet, WorkspaceType


# Load environment variables from .env
dotenv.load_dotenv()

#class Model(str, Enum):
#    OPENAI = "openai"
#
#model = Model.OPENAI

#client = ChatOpenAI(
#    api_key=os.environ["OPENAI_API_KEY"],  # type: ignore
#    model="gpt-4-1106-preview",
#)

llm = HuggingFacePipeline.from_model_id(
    model_id="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B",
    task="text-generation"
)

client = ChatHuggingFace(llm=llm)

def get_crew(repo_path: str, workspace_id: str):

    composio_toolset = ComposioToolSet(
        workspace_config=WorkspaceType.Host(),
        metadata={
            App.CODE_ANALYSIS_TOOL: {
                "dir_to_index_path": repo_path,
            }
        },
    )
    if workspace_id:
        composio_toolset.set_workspace_id(workspace_id)

    # Get required tools
    tools = [
        *composio_toolset.get_tools(
            apps=[
                App.FILETOOL,
                App.SHELLTOOL,
                App.CODE_ANALYSIS_TOOL,
            ]
        ),
    ]

    # Define agent
    agent = Agent(
        role=ROLE,
        goal=GOAL,
        backstory=BACKSTORY,
        llm=client,
        tools=tools,
        verbose=True,
    )

    task = Task(
        description=DESCRIPTION,
        expected_output=EXPECTED_OUTPUT,
        agent=agent,
    )

    crew = Crew(
        agents=[agent],
        tasks=[task],
        process=Process.sequential,
        verbose=True,
        cache=False,
        memory=True,
    )
    return crew, composio_toolset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant