Skip to main content

margin-core

The shared core of margin, a collection of small AI agents that answer with evidence. You need this package to write an agent. To use one, install the agent (for example margin-ai-code-detector) together with margin-cli or margin-api.

pip install margin-core

What's in it

An agent is a class with an input model, an output model and an async run method. You call it through execute(), which validates the input, times the run, counts model usage, and turns a crash into an error result instead of an exception. Every agent returns the same AgentResult: a summary, findings, the evidence for each finding, warnings, and whatever typed data the agent wants to add.

Agents register under the margin.agents entry point, so installing one is all it takes for the CLI, the API and the web UI to find it.

The model client gives you one interface to local OpenAI-compatible servers (Ollama, LM Studio, llama.cpp, vLLM), Anthropic and OpenAI. It retries, tracks tokens and cost, and stops at a spending limit you set. MockLLM returns canned answers, which keeps tests offline.

The loaders turn a local folder or a GitHub repository into a Workspace: the files worth reading, the files that were skipped and why, and the git history. A repository is size-checked before it is cloned, and nothing in it is ever run.

A minimal agent

from pydantic import BaseModel
from margin_core import AgentInput, AgentResult, BaseAgent, RunContext


class GreetInput(AgentInput):
    name: str


class GreetOutput(BaseModel):
    greeting: str


class Greeter(BaseAgent):
    id = "greeter"
    name = "Greeter"
    description = "Says hello."
    version = "0.1.0"
    InputModel = GreetInput
    OutputModel = GreetOutput

    async def run(self, input: GreetInput, ctx: RunContext) -> AgentResult:
        greeting = f"Hello, {input.name}!"
        return self.make_result(summary=greeting, output=GreetOutput(greeting=greeting))

Register it in your package's pyproject.toml:

[project.entry-points."margin.agents"]
greeter = "my_package.agent:Greeter"

The full guide is docs/writing-an-agent.md.

Settings

Model settings are read from environment variables first, then from settings saved in the web UI, then from a .env file. The ones you are likely to need are DEFAULT_LLM_PROVIDER (local, anthropic or openai), LOCAL_LLM_BASE_URL, LOCAL_LLM_MODEL, ANTHROPIC_API_KEY, OPENAI_API_KEY and MAX_COST_USD. .env.example lists them all.

License

MIT

Metadata

Release files for margin-core 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for margin-core 0.1.0
File Size Uploaded Provenance
margin_core-0.1.0.tar.gz 50.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for margin-core 0.1.0
File Interpreter ABI Platform
margin_core-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 99.2 kB

Release files / margin_core-0.1.0.tar.gz

Download URL margin_core-0.1.0.tar.gz
Size 50.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9fcdb64b2496c6f44e6eb66b0e961c5183d4afeb5f525e9d145eb6e98999cada
BLAKE2b-256 checksum
How to use checksums
fcd5de702dabd120636a03aef1a05030dc52106a43db649e82ef97397a378dd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Release files / margin_core-0.1.0-py3-none-any.whl

Download URL margin_core-0.1.0-py3-none-any.whl
Size 49.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7df0e5fb9767955ffab7bead0f48612213ec38a14a029d19ce107395bc5b81b0
BLAKE2b-256 checksum
How to use checksums
62322c920f9f54b05e23548010bb3cfd01b8ff815fb25b2b322d2ffb4a3ffe75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

Security for margin-core 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for margin_core-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page