Skip to content

Commit

Permalink
fix: ensure subagent logdir unique
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBjare committed Oct 16, 2024
1 parent 6fa6155 commit f735111
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions gptme/tools/subagent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@

import json
import logging
import random
import string
import threading
from dataclasses import asdict, dataclass
from pathlib import Path
from typing import TYPE_CHECKING, Literal

from ..message import Message
Expand Down Expand Up @@ -36,15 +39,13 @@ class Subagent:
agent_id: str
prompt: str
thread: threading.Thread
logdir: Path

def get_log(self) -> "LogManager":
# noreorder
from gptme.cli import get_logdir # fmt: skip

from ..logmanager import LogManager # fmt: skip

name = f"subagent-{self.agent_id}"
return LogManager.load(get_logdir(name))
return LogManager.load(self.logdir)

def status(self) -> ReturnType:
if self.thread.is_alive():
Expand Down Expand Up @@ -76,8 +77,12 @@ def subagent(agent_id: str, prompt: str):

from ..prompts import get_prompt # fmt: skip

def random_string(n):
s = string.ascii_lowercase + string.digits
return "".join(random.choice(s) for _ in range(n))

name = f"subagent-{agent_id}"
logdir = get_logdir(name)
logdir = get_logdir(name + "-" + random_string(4))

def run_subagent():
prompt_msgs = [Message("user", prompt)]
Expand Down Expand Up @@ -111,7 +116,7 @@ def run_subagent():
daemon=True,
)
t.start()
_subagents.append(Subagent(agent_id, prompt, t))
_subagents.append(Subagent(agent_id, prompt, t, logdir))


def subagent_status(agent_id: str) -> dict:
Expand Down

0 comments on commit f735111

Please sign in to comment.