Skip to main content

Python SDK for the MindRoot API

Project description

MindRoot Python SDK

A simple Python client for interacting with the MindRoot API. This SDK provides programmatic access to run tasks with MindRoot AI agents.

Installation

You can install the package directly from GitHub:

pip install git+https://github.com/mindroot/mindroot-python-sdk.git

Or install from a local copy:

pip install -e .

Quick Start

from mrsdk import MindRootClient

# Initialize client with your API key
client = MindRootClient(api_key="your_api_key_here")

# Or use environment variable
# export MINDROOT_API_KEY=your_api_key_here
# client = MindRootClient()

# Run a task with an agent
result = client.run_task(
    agent_name="Assistant",
    instructions="What is the square root of 256? Show your work."
)

# Print the result
print(result["results"])

Advanced Usage

Getting the Full Trace

result = client.run_task(
    agent_name="Assistant",
    instructions="Please write a program to calculate the first 10 prime numbers.",
    include_trace=True
)

# Print the result
print(result["results"])

# Print the full trace of commands executed by the agent
import json
for cmd in result["full_results"]:
    print(json.dumps(cmd, indent=2))

Handling Errors

from mrsdk import MindRootClient, MindRootError

client = MindRootClient()

try:
    result = client.run_task("Assistant", "Complex task instructions here")
    print(result["results"])
except MindRootError as e:
    print(f"Error from MindRoot API: {e}")
except Exception as e:
    print(f"Unexpected error: {e}")

Changing the Base URL

# For connecting to a custom MindRoot instance
client = MindRootClient(
    api_key="your_api_key",
    base_url="https://mindroot.your-company.com",
    timeout=600  # Increase timeout for complex tasks (in seconds)
)

Command-line Interface

The package includes a simple command-line interface for quick testing:

# Set your API key
export MINDROOT_API_KEY=your_api_key_here

# Run the example script
python -m mrsdk.cli "What is the square root of 256? Show your work."

# Include full trace in the output
python -m mrsdk.cli "Calculate the first 10 prime numbers." --trace

# Specify a different agent
python -m mrsdk.cli "Translate this to French: Hello, world!" --agent Translator

API Reference

MindRootClient

client = MindRootClient(api_key=None, base_url="http://localhost:8012", timeout=300)

Parameters:

  • api_key (str, optional): Your MindRoot API key. If not provided, it will look for the MINDROOT_API_KEY environment variable.
  • base_url (str): Base URL of the MindRoot API server. Default is http://localhost:8012.
  • timeout (int): Request timeout in seconds. Default is 300 (5 minutes).

Methods

run_task

result = client.run_task(agent_name, instructions, include_trace=False)

Parameters:

  • agent_name (str): Name of the agent to run the task.
  • instructions (str): Instructions or prompt for the agent.
  • include_trace (bool): Whether to include the full trace of commands in the result. Default is False.

Returns:

A dictionary containing the task results:

  • If include_trace is False, returns only the final textual result.
  • If include_trace is True, returns a dict with 'results', 'full_results', and 'log_id' keys.

Raises:

  • MindRootError: If the API returns an error or if the request fails.
  • requests.RequestException: For network-related errors.

License

MIT

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

mrsdk-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

mrsdk-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file mrsdk-0.1.0.tar.gz.

File metadata

  • Download URL: mrsdk-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.12

File hashes

Hashes for mrsdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ff2b83561c360aa7f7a6cc5ad5d147651579778a5147a65073ce5e0e53b488b
MD5 9cd4b5cb94b9bbf1965a593712748658
BLAKE2b-256 ed1b5007f80af4fd3dca2b33a5c81d8d475aa9dcc56dcd108b2c1b72081859b2

See more details on using hashes here.

File details

Details for the file mrsdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mrsdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.12

File hashes

Hashes for mrsdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be498a9125bd5ec52e6e0e72b0ef651d858807deffd759d3d08399944551d35d
MD5 824af124cb07b28af12476423de72ae0
BLAKE2b-256 bb4d7e51720261f2b4cee5eddad58d2430033eaccd9761fbcf2b91d45a9f00a6

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