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.1

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.1
File Size Uploaded Provenance
margin_core-0.1.1.tar.gz 53.3 kB With provenance Details

Built distribution (wheel)

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

Total release size: 103.2 kB

Release files / margin_core-0.1.1.tar.gz

Download URL margin_core-0.1.1.tar.gz
Size 53.3 kB
Tags Source
SHA-256 checksum
How to use checksums
832d586fb9496e95b07cdce8dd23ac59ab5b811d694a1318c8c027c43f111543
BLAKE2b-256 checksum
How to use checksums
31c98925c0fd07d0922aef3ad009540ac94198aa53bb0118ba471d211aae3f8f
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.1-py3-none-any.whl

Download URL margin_core-0.1.1-py3-none-any.whl
Size 49.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
784d1183d21bbb630ca129c11fd45647490c88d66103b46b79a18ec976f35900
BLAKE2b-256 checksum
How to use checksums
4d14d42affb68fcf774a947587d4e8cd7fb96f609eeaec3ba08e8a235cbd0a70
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.1

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.1.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.1 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