Skip to content

Commit

Permalink
fixed the broken memory
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkulaga committed Nov 27, 2024
1 parent e32025b commit f533a10
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 100 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,5 @@ cython_debug/

.micromamba/

*.egg-info
*.egg-info
/config #ignore only config folder that tests write by mistake
74 changes: 74 additions & 0 deletions coding/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# just-agents-coding

A submodule of just-agents focused on code generation and execution capabilities.

## Overview

just-agents-coding provides secure code execution environments and tools for LLM-powered coding agents. It enables safe code generation and execution through containerized environments, protecting your system while allowing AI agents to write and test code.

## Key Features

- 🔒 Secure code execution through isolated containers
- 🐳 Multiple specialized containers:
- Standard sandbox for general Python code
- Biosandbox for bioinformatics tasks
- Websandbox for web-related code
- 📁 Simple I/O management with mounted `/input` and `/output` directories
- 🔍 Code execution monitoring and logging

## Quick Start

```bash
pip install just-agents-coding
```

## Usage Example

```python
from just_agents.base_agent import BaseAgent
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Initialize agent from configuration
agent = BaseAgent.from_yaml("SimpleCodeAgent", file_path="path/to/coding_agents.yaml")

# Execute code through the agent
result = agent.query("""
Get FGF2 human protein sequence from uniprot using biopython.
As a result, return only the sequence
""")

print(result)
```

## Container Types

### Standard Sandbox
- General Python code execution
- Basic Python packages pre-installed
- Isolated from host system

### Biosandbox
- Specialized for bioinformatics tasks
- Includes common bio packages (Biopython, etc.)
- Safe handling of biological data

### Websandbox
- Web development and testing
- Network access controls
- Common web frameworks available

## Security Features

- Root access disabled in containers
- Resource usage limits
- Network isolation
- Temporary file system
- Controlled package installation

## Documentation

For more detailed documentation and examples, visit:
- [Basic Usage Tutorial](examples/notebooks/03_coding_agent.ipynb)
2 changes: 1 addition & 1 deletion core/just_agents/base_memory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

from pydantic import BaseModel, Field, PrivateAttr
from typing import Optional, Callable, List, Dict, Union
from functools import singledispatchmethod
Expand Down Expand Up @@ -80,6 +79,7 @@ def add_system_message(self, prompt: str) -> None:
def add_user_message(self, prompt: str) -> None:
self.add_message({"role": Role.user, "content": prompt})

@property
def last_message_str(self) -> Optional[str]:
message_str = None
last_message = self.last_message
Expand Down
2 changes: 1 addition & 1 deletion core/just_agents/patterns/interfaces/IThinkingAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def thought_query(self, response: AbstractQueryInputType, **kwargs) -> THOUGHT_T

def think(self,
query: AbstractQueryInputType,
max_iter: int = 3,
max_iter: int = 8,
chain: Optional[list[THOUGHT_TYPE]] = None,
**kwargs ) -> tuple[Optional[THOUGHT_TYPE], Optional[list[THOUGHT_TYPE]]]:
"""
Expand Down
Empty file.
16 changes: 4 additions & 12 deletions examples/just_agents/examples/basic/agent_profiles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,15 @@ agent_profiles:
tool_choice: auto
tools: []
tools:
get_current_weather:
mock_get_current_weather:
arguments:
- location:
default: null
kind: POSITIONAL_OR_KEYWORD
type_annotation: <class 'str'>
description: 'Gets the current weather in a given location.
Args:
location (str): The name of the location to get the weather for.
Returns:
str: A JSON string containing the location, temperature, and unit of measurement.'
function: get_current_weather
package: just_agents_examples.tools
description: Gets the current weather in a given location
function: mock_get_current_weather
package: just_agents.tools.weather
parameters:
properties:
location:
Expand Down
10 changes: 5 additions & 5 deletions examples/just_agents/examples/basic/agent_serialization.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from dotenv import load_dotenv
from pathlib import Path

from just_agents.examples.tools import get_current_weather

from just_agents.tools.weather import mock_get_current_weather
from just_agents import llm_options
from just_agents.base_agent import BaseAgent
from just_agents.just_profile import JustAgentProfile
Expand All @@ -23,7 +22,7 @@
created_agent = BaseAgent(
llm_options=llm_options.LLAMA3_2_VISION,
config_path=config_path,
tools=[get_current_weather]
tools=[mock_get_current_weather]
)

created_agent.save_to_yaml("SimpleWeatherAgent")
Expand All @@ -35,8 +34,9 @@
assert isinstance(agent_auto, BaseAgent)
assert agent_auto.to_json() == created_agent.to_json()
res = agent_auto.query("What's the weather like in San Francisco, Tokyo, and Paris?")
print("===============")
print(res)
print(agent_auto.to_json())
#print(agent_auto.to_json())

#yaml constructor example
agent = BaseAgent.from_yaml("SimpleWeatherAgent", file_path=config_path)
Expand All @@ -46,4 +46,4 @@
assert agent.to_json() == created_agent.to_json()
res = agent.query("What's the weather like in San Francisco, Tokyo, and Paris?")
print(res)
print(agent.to_json())
#print(agent.to_json())
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dotenv import load_dotenv
from just_agents import llm_options
from just_agents.patterns.chain_of_throught import ChainOfThoughtAgent
from examples.tools import letter_count
from examples.just_agents.examples.tools import letter_count
import pprint

# Get the directory path where this example is located
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dotenv import load_dotenv
from examples.coding.mounts import coding_examples_dir
from just_agents.examples.coding.mounts import coding_examples_dir
from just_agents.patterns.chain_of_throught import ChainOfThoughtAgent
from just_agents import llm_options
import pprint
Expand Down
File renamed without changes.
74 changes: 0 additions & 74 deletions just-agents-coding/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions just_agents/__init__.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_chain_of_thought.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_function_query():

llm_options = just_agents.llm_options.OPENAI_GPT4oMINI.copy()
agent: ChainOfThoughtAgent = ChainOfThoughtAgent(llm_options=llm_options, tools=[count_letters])
result, thoughts = agent.think("Count the number of occurrences of the letter ’L’ in the word - LOLLAPALOOZA.")
result, thoughts = agent.think("Count the number of occurrences of the letter 'L' in the word - 'LOLLAPALOOZA'.")
print("Thoughts: ", thoughts)
print("Results: ", result)
assert "4" in result.content
2 changes: 1 addition & 1 deletion tests/test_serialization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from dotenv import load_dotenv
import just_agents.llm_options
from examples.tools import get_current_weather
from examples.just_agents.examples.tools import get_current_weather

from just_agents.base_agent import BaseAgent
from just_agents.just_profile import JustAgentProfile
Expand Down

0 comments on commit f533a10

Please sign in to comment.