Skip to main content

Official Python client and SDK for the LibreFang Agent OS

Project description

LibreFang Python SDK

Official Python client and SDK for the LibreFang Agent OS.

Installation

pip install librefang

Two Packages

This package provides two different interfaces:

1. REST API Client (librefang.client)

Control LibreFang remotely via its REST API.

from librefang import Client

client = Client("http://localhost:4545")

# Create an agent
agent = client.agents.create(template="assistant")
print(f"Agent created: {agent['id']}")

# Send a message
reply = client.agents.message(agent["id"], "Hello!")
print(reply)

# Stream a response
for event in client.agents.stream(agent["id"], "Tell me a story"):
    if event.get("type") == "text_delta":
        print(event["delta"], end="", flush=True)

2. Agent SDK (librefang.sdk)

Write Python agents that run inside LibreFang.

from librefang import Agent

agent = Agent()

@agent.on_message
def handle(message: str, context: dict) -> str:
    return f"You said: {message}"

agent.run()

Or use the simple input/output functions:

from librefang import read_input, respond

data = read_input()
result = f"Echo: {data['message']}"
respond(result)

Examples

See the examples/ directory for more examples:

Client Examples

  • client_basic.py - Basic REST API usage
  • client_streaming.py - Streaming responses

SDK Examples

  • echo_agent.py - Simple echo agent

Requirements

  • Python 3.8+

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

librefang_sdk-0.5.4.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

librefang_sdk-0.5.4-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file librefang_sdk-0.5.4.tar.gz.

File metadata

  • Download URL: librefang_sdk-0.5.4.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for librefang_sdk-0.5.4.tar.gz
Algorithm Hash digest
SHA256 71d0698a255ebbda5a9350944bef10bc63f65092702f254ffc36a17bad8a6ef2
MD5 c64629d65022c718ab981f2101d88c6c
BLAKE2b-256 06618a1bd2cfd2b09b80bdbfdac320c254ec3c32d6569048ee915c6c8ae89e16

See more details on using hashes here.

File details

Details for the file librefang_sdk-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: librefang_sdk-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for librefang_sdk-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a4a4e9a717123a7ee852c1454d84622ecfab3165dd22fdf0f0b13e257404aac2
MD5 20eddda54f573dc3105a96faab3391d3
BLAKE2b-256 5d10b958116497ab42a18cda421c9c526338428b74ccae09f4f8cbb1fc089ff5

See more details on using hashes here.

Supported by

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