Skip to main content

Official Python SDK for SharpAIKit - .NET AI/LLM Toolkit with Agent, Chain, Memory, RAG, Graph, and more

Project description

SharpAIKit Python SDK

PyPI version Python 3.8+ License: MIT

Official Python SDK for SharpAIKit - A powerful .NET AI/LLM toolkit that surpasses LangChain in functionality, performance, and developer experience.

🚀 Features

  • Agent Execution - Synchronous, asynchronous, and streaming execution
  • Skill System - Enterprise-grade behavior governance
  • Chain (LCEL) - LangChain-style chain composition
  • Memory - Multiple memory strategies (Buffer, Window, Summary, Vector, Entity)
  • RAG - Retrieval-Augmented Generation with document indexing
  • SharpGraph - Graph-based agent orchestration
  • Code Interpreter - Native C# code execution
  • DSPy Optimizer - Automatic prompt optimization
  • Multi-Modal - Image and vision support
  • Observability - Logging, metrics, and tracing

📦 Installation

pip install sharpaikit

Prerequisites

  • Python 3.8 or higher
  • .NET 8.0 SDK (for building the gRPC host - see setup below)

🎯 Quick Start

Basic Usage

from sharpaikit import Agent

# Create agent (automatically starts gRPC host if needed)
agent = Agent(
    api_key="your-api-key",
    base_url="https://api.openai.com/v1",
    model="gpt-3.5-turbo",
    auto_start_host=True
)

# Run a task
result = agent.run("What is 2 + 2?")
print(result.output)
print(f"Success: {result.success}")
print(f"Steps: {len(result.steps)}")

# Cleanup
agent.close()

With Tools

tools = [
    {
        "name": "calculator",
        "description": "Performs arithmetic operations",
        "parameters": [
            {
                "name": "expression",
                "type": "string",
                "description": "Mathematical expression",
                "required": True
            }
        ]
    }
]

result = agent.run(
    task="Calculate 25 * 37",
    tools=tools
)

Streaming

for chunk in agent.run_stream("Tell me a story"):
    if chunk.output:
        print(chunk.output, end="", flush=True)

Using Other Services

from sharpaikit import Chain, Memory, RAG, Graph
from sharpaikit import UnifiedGrpcClient

client = UnifiedGrpcClient(host="localhost", port=50051)

# Chain service
chain = Chain(client)
chain.create_llm_chain("my_chain", api_key="...", model="gpt-4")
result = chain.invoke("my_chain", context={"input": "Hello"})

# Memory service
memory = Memory(client)
memory.create("my_memory", "Buffer")
memory.add_message("my_memory", ChatMessage(role="user", content="Hello"))

# RAG service
rag = RAG(client)
rag.create("my_rag", api_key="...")
rag.index_content("my_rag", "Your document content here")
answer = rag.ask("my_rag", "What is this about?")

🔧 Setup gRPC Host

The Python SDK communicates with a C# gRPC host. You need to build and run it:

# Clone the repository
git clone https://github.com/dxpython/SharpAIKit.git
cd SharpAIKit

# Build the gRPC host
dotnet build src/SharpAIKit.Grpc.Host/SharpAIKit.Grpc.Host.csproj -c Release

# Run the host (or let the SDK auto-start it)
dotnet run --project src/SharpAIKit.Grpc.Host/SharpAIKit.Grpc.Host.csproj

The SDK can automatically start the host if auto_start_host=True (default).

📚 Documentation

🎯 Supported Services

Service Status Description
Agent ✅ Full Agent execution with tools and skills
Chain ✅ Full LCEL-style chain composition
Memory ✅ Full Conversation memory management
RAG ✅ Full Retrieval-Augmented Generation
Graph ✅ Full SharpGraph orchestration
Prompt ✅ Full Prompt template management
OutputParser ✅ Full Output parsing utilities
DocumentLoader ✅ Full Multi-format document loading
CodeInterpreter ✅ Full C# code execution
Optimizer ✅ Full DSPy-style prompt optimization
Tool ✅ Full Tool registration and management
Observability ✅ Full Logging, metrics, and tracing

🔑 API Reference

Agent Class

agent = Agent(
    api_key: str,
    model: str = "gpt-3.5-turbo",
    base_url: str = "https://api.openai.com/v1",
    skills: Optional[List[str]] = None,
    agent_id: Optional[str] = None,
    host: str = "localhost",
    port: int = 50051,
    auto_start_host: bool = True,
)

Methods:

  • run(task, tools=None, context=None) - Execute synchronously
  • run_stream(task, tools=None, context=None) - Stream results
  • run_async(task, tools=None, context=None) - Execute asynchronously
  • get_skill_resolution() - Get last skill resolution
  • list_available_skills() - List all available skills
  • close() - Cleanup resources

Other Services

All services follow a similar pattern:

from sharpaikit import Chain, Memory, RAG, Graph, Prompt, OutputParser
from sharpaikit import DocumentLoader, CodeInterpreter, Optimizer, Tool, Observability

client = UnifiedGrpcClient()
service = ServiceName(client)
# Use service methods...

🛠️ Error Handling

from sharpaikit.errors import (
    SharpAIKitError,
    ExecutionError,
    ConnectionError,
    AgentNotFoundError,
    SkillResolutionError,
)

try:
    result = agent.run("Task")
except ExecutionError as e:
    print(f"Execution failed: {e}")
    if e.denied_tools:
        print(f"Denied tools: {e.denied_tools}")
except ConnectionError as e:
    print(f"Connection failed: {e}")

📋 Requirements

  • Python 3.8+
  • grpcio >= 1.60.0
  • grpcio-tools >= 1.60.0
  • httpx >= 0.24.0
  • .NET 8.0 SDK (for gRPC host)

🤝 Contributing

Contributions are welcome! Please see the main repository for contribution guidelines.

📄 License

MIT License - see LICENSE file for details.

🙏 Acknowledgments

  • Built on top of SharpAIKit (.NET)
  • Inspired by LangChain and other AI frameworks
  • Powered by gRPC for high-performance cross-language communication

🔗 Links

📞 Support

For issues and questions:


Made with ❤️ by the SharpAIKit Team

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

sharpaikit-0.3.0.tar.gz (115.8 kB view details)

Uploaded Source

Built Distribution

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

sharpaikit-0.3.0-py3-none-any.whl (47.7 kB view details)

Uploaded Python 3

File details

Details for the file sharpaikit-0.3.0.tar.gz.

File metadata

  • Download URL: sharpaikit-0.3.0.tar.gz
  • Upload date:
  • Size: 115.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for sharpaikit-0.3.0.tar.gz
Algorithm Hash digest
SHA256 12e34c5280425ebb81c0577aca487a183bebb2d670cef801991773c3f3470f03
MD5 4e533c3d30cf38165f23f058ae7a4d84
BLAKE2b-256 683d8f997da22c24372f689a828ad57198b95728c36f51faba796b3efc956a45

See more details on using hashes here.

File details

Details for the file sharpaikit-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: sharpaikit-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 47.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.6

File hashes

Hashes for sharpaikit-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb646a33a3476729eab2fc012a63d86d2056b4e91f535953a54376cca3f5ed2c
MD5 d44e558d27a19e82b38cacff0b834605
BLAKE2b-256 6d96d1c20c705f7d35aa712500216738608054a2243e5d57a400855c77c9472c

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