Skip to main content

Agent framework for constructing language model agents and training on constructive tasks.

Project description

ldp

Agent framework for constructing language model agents and training on constructive tasks.

This repo models agent-environment interactions using a Partially Observable Markov Decision Process (POMDP). Inspired by POMDP, this repo's name ldp stands for Language Decision Processes.

Installation

To install ldp:

pip install -e .

If you plan to export Graphviz visualizations, make sure you also install the graphviz library into your OS via:

  • Linux: apt install graphviz
  • macOS: brew install graphviz

Agent/Policy

An agent should have two functions:

agent_state = await agent.init_state(tools=tools)
new_action, new_agent_state, value = await agent.get_asv(
    agent_state, obs
)

An agent should have a function get_asv(agent_state, obs) that chooses an action (a) from the observation messages, and returns the next agent state (s) and a value estimate (v). The first argument, agent_state, is a state specific for the agent that can be used for training from episodes. You can make it None if you aren't using it. It could contain things like agent memory.

The obs are not the complete list of observations, but rather the last list from env.step. The agent should keep track of observations via its state if it would like to keep them.

The value can be 0, it is the agent's estimate of the future rewards given its state and observations. This is used for training.

Generic Support

The Agent (as well as classes in agent.ops) are generics, which means:

  • Agent is designed to support arbitrary types
  • Subclasses can exactly specify state types, making the code more readable

If you are new to Python generics (typing.Generic), please read about them in Python typing.

Below is how to specify an agent with a custom state type.

from dataclasses import dataclass, field
from datetime import datetime

from ldp.agents import Agent


@dataclass
class MyComplexState:
    vector: list[float]
    timestamp: datetime = field(default_factory=datetime.now)


class MyAgent(Agent[MyComplexState]):
    """Some agent who is now type checked to match the custom state."""

Complete Example

from ldp.agent import SimpleAgent
from aviary.env import DummyEnv

env = DummyEnv()
agent = SimpleAgent()

obs, tools = await env.reset()
agent_state = await agent.init_state(tools=tools)

done = False
while not done:
    action, agent_state, _ = await agent.get_asv(agent_state, obs)
    obs, reward, done, truncated = await env.step(action.value)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ldp-0.14.0.tar.gz (354.1 kB view details)

Uploaded Source

Built Distribution

ldp-0.14.0-py3-none-any.whl (97.9 kB view details)

Uploaded Python 3

File details

Details for the file ldp-0.14.0.tar.gz.

File metadata

  • Download URL: ldp-0.14.0.tar.gz
  • Upload date:
  • Size: 354.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ldp-0.14.0.tar.gz
Algorithm Hash digest
SHA256 e0813524fd3108adf6d9d5989704485f35619eeab89c42049c346cd86ed56dd0
MD5 b82e9b2bdcad5c0825dfd76f5a3988f8
BLAKE2b-256 900175c6a62f06c0450e41b54beddf427d12ade7df9fc72b85b1e30a67dd196f

See more details on using hashes here.

File details

Details for the file ldp-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: ldp-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 97.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for ldp-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ffa8d5fe24d36d6784e32ea96ea73fa565307ccc945ed6f00c63fb301d093bd
MD5 b1fe5bb09155dea7a733631265d068a4
BLAKE2b-256 62fe9f8dafecc76a94765179f8734f9ebe70657d4cfaa085c08d861cb3d42c0d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page