Skip to content

Commit

Permalink
papayne/skills 6 (#266)
Browse files Browse the repository at this point in the history
Skill Assistant:

- Add startup routine/action w/ start method.-
- Add clear method.
- Add drive_root and metadrive_root to assistant registry.
- Fixes state_meachine_routine_runner methods (await).
- Enables tests in form_filler_skill.

FormFillerSkill/GuidedConversationSkill:

- Make Agenda a Pydantic model (separate mutations/functions into a
functional approach).
- Remove BaseModelLLM in deference to built-in validation.
- Adds drives.
- Separates init/step initialization.
- Creates definitions module (adds acrostic_poem).
- Properly manages artifacts, agenda and other state in run stack
frames.
- Adds separate logging module to avoid cyclical dependencies.

---------

Co-authored-by: Paul Payne <[email protected]>
  • Loading branch information
payneio and Paul Payne authored Nov 26, 2024
1 parent c2d72ee commit 57aa905
Show file tree
Hide file tree
Showing 42 changed files with 2,302 additions and 930 deletions.
7 changes: 5 additions & 2 deletions assistants/skill-assistant/assistant/assistant_registry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import asyncio
import logging
from os import PathLike
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -53,6 +54,8 @@ async def register_assistant(
event_mapper: SkillEventMapperProtocol,
chat_driver_config: ChatDriverConfig,
skills: dict[str, Skill] | None = None,
drive_root: PathLike | None = None,
metadata_drive_root: PathLike | None = None,
) -> Assistant:
"""
Define the skill assistant that you want to have backing this assistant
Expand All @@ -67,8 +70,8 @@ async def register_assistant(
assistant = Assistant(
name="Assistant",
assistant_id=assistant_id,
drive_root=Path(".data") / assistant_id / "assistant",
metadata_drive_root=Path(".data") / assistant_id / ".assistant",
drive_root=drive_root or Path(".data") / assistant_id / "assistant",
metadata_drive_root=metadata_drive_root or Path(".data") / assistant_id / ".assistant",
chat_driver_config=chat_driver_config,
skills=skills,
)
Expand Down
15 changes: 13 additions & 2 deletions assistants/skill-assistant/assistant/skill_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Any, Optional

import openai_client
from assistant_drive import Drive, DriveConfig
from content_safety.evaluators import CombinedContentSafetyEvaluator
from form_filler_skill import FormFillerSkill
from form_filler_skill.guided_conversation import GuidedConversationSkill
Expand Down Expand Up @@ -174,7 +175,11 @@ async def respond_to_conversation(
await conversation_context.update_participant_me(UpdateParticipant(status="thinking..."))

# Get an assistant from the skill library.
assistant = assistant_registry.get_assistant(conversation_context.id)
assistant_id = conversation_context.id
assistant = assistant_registry.get_assistant(assistant_id)
drive_root = Path(".data") / assistant_id / "assistant"
metadata_drive_root = Path(".data") / assistant_id / ".assistant"
drive = Drive(DriveConfig(root=drive_root))

# Create and register an assistant if necessary.
if not assistant:
Expand All @@ -191,19 +196,25 @@ async def respond_to_conversation(
chat_driver_config,
{
"posix": PosixSkill(
name="posix",
sandbox_dir=Path(".data") / conversation_context.id,
chat_driver_config=chat_driver_config,
mount_dir="/mnt/data",
),
"form_filler": FormFillerSkill(
name="form_filler",
chat_driver_config=chat_driver_config,
language_model=language_model,
),
"guided_conversation": GuidedConversationSkill(
chat_driver_config=chat_driver_config,
name="guided_conversation",
language_model=language_model,
drive=drive.subdrive("guided_conversation"),
chat_driver_config=chat_driver_config,
),
},
drive_root=drive_root,
metadata_drive_root=metadata_drive_root,
)

except Exception as e:
Expand Down
134 changes: 132 additions & 2 deletions assistants/skill-assistant/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libraries/python/assistant-drive/assistant_drive/drive.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IfDriveFileExistsBehavior(StrEnum):

class DriveConfig(BaseModel):
root: str | PathLike
default_if_exists_behavior: IfDriveFileExistsBehavior = IfDriveFileExistsBehavior.AUTO_RENAME
default_if_exists_behavior: IfDriveFileExistsBehavior = IfDriveFileExistsBehavior.OVERWRITE


class FileMetadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_open_non_existent_file(drive):

def test_auto_rename(drive, if_exists=IfDriveFileExistsBehavior.AUTO_RENAME):
drive.write(file_content, "test.txt", "summaries")
metadata = drive.write(file_content, "test.txt", "summaries")
metadata = drive.write(file_content, "test.txt", "summaries", if_exists=IfDriveFileExistsBehavior.AUTO_RENAME)
assert metadata.filename == "test(1).txt"
assert sorted(list(drive.list(dir="summaries"))) == sorted(["test.txt", "test(1).txt"])

Expand Down
9 changes: 9 additions & 0 deletions libraries/python/context/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ events = { path = "../events", editable = true }
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.pytest.ini_options]
addopts = "-vv"
log_cli = true
log_cli_level = "WARNING"
log_cli_format = "%(asctime)s | %(levelname)-7s | %(name)s | %(message)s"
testpaths = ["tests"]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"
Loading

0 comments on commit 57aa905

Please sign in to comment.