Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Agiflow Software Development Kit (SDK) for Python, support LLM APIs and Frameworks tracing with Opentelemetry and more.
Welcome to the agiflow-sdk
documentation. This guide will help you integrate with the Agiflow Python SDK quickly and easily. The SDK provides automatic and manual tracing capabilities for LLM apis and frameworks, as well as helpers to interact with backend APIs.
You can install the agiflow-sdk
using either pip
or poetry
.
pip install agiflow-sdk
The agiflow-sdk
offers the following functionalities:
Open Telemetry
.Initialize the agiflow-sdk
client at the entry point of your application:
from agiflow import Agiflow
Agiflow.init(
app_name="<YOUR_APP_NAME>",
api_key="<AGIFLOW_API_KEY>" # Or set AGIFLOW_API_KEY environment variable
)
You can find the API key on the Environment > Settings > API Key
page on the Agiflow Dashboard.
Once set up, if you run your backend application with supported LLM frameworks, traces should be logged on the Agiflow dashboard under Environment > Logs
.
NOTE: Agiflow uses a separate global Open Telemetry trace provider to ensure all LLM traces are sent to support user feedback. To use the default Open Telemetry global trace provider, set the AGIFLOW_OTEL_PYTHON_TRACER_PROVIDER_GLOBAL
environment variable to true
.
Traces are automatically logged when you set up Agiflow at the top of your application. By default, these traces are limited to backend applications and are not synchronized with frontend tracking.
If you haven't integrated with the frontend SDK, you can still associate Open Telemetry trace with user and session using the following method:
from agiflow import Agiflow
Agiflow.set_association_properties({
"user_id": "<USER_ID>", # Optional
"session_id": "<SESSION_ID>", # Optional
"task_name": "<TASK_NAME>", # Optional, to label feedback task
});
If you have set up frontend tracing for Web, your backend should have access to x-agiflow-trace-id
in the HTTP headers.
Use our header to associate frontend tracing with Open Telemetry tracing as follows:
from agiflow import Agiflow
from agiflow.opentelemetry import extract_association_properties_from_http_headers
Agiflow.set_association_properties(extract_association_properties_from_http_headers(request.headers))
set_association_properties
action_id
to the trace context.action_id
, task_id
, and session_id
to the trace context.You might want to log additional information that is important to your AI workflow or for tools that are not supported by Agiflow yet. In these cases, use manual tracing to add this information. These decorators support the following arguments:
Trace the workflow with a unique name and extra information using the following methods:
from agiflow.opentelemetry import aworkflow
@aworkflow(name="<WORKFLOW_NAME>", method_name="bar")
class Foo:
async def bar(self):
...
Trace the task with a unique name and extra information using the following methods:
from agiflow.opentelemetry import atask
@atask(name="<TASK_NAME>", method_name="bar")
class Foo:
async def bar(self):
...
Trace the agent with a unique name and extra information using the following methods:
from agiflow.opentelemetry import aagent
@aagent(name="<AGENT_NAME>", method_name="bar")
class Foo:
async def bar(self):
...
Trace the tool with a unique name and extra information using the following methods:
from agiflow.opentelemetry import atool
@atool(name="<TOOL_NAME>", method_name="bar")
class Foo:
async def bar(self):
...
If you are using an event-driven architecture, additional steps are required to enable trace flow throughout the workflow.
Extract the current trace context and pass it to the message queue system as follows:
from agiflow.opentelemetry import get_carrier_from_trace_context
carrier = get_carrier_from_trace_context()
# Pass carrier information to the message queue
kafkaClient.produce({
...
"otlp_carrier": carrier,
})
Retrieve the carrier
information from the message and restore the context from the carrier information:
from agiflow.opentelemetry import get_trace_context_from_carrier, get_tracer
carrier = message.get("otlp_carrier")
ctx = get_trace_context_from_carrier(carrier)
with get_tracer() as tracer:
with tracer.start_as_current_span('job', ctx):
...
The children span
uses the same context and parent span
, so you don't need to pass context around. Traces from the consumer will use the same context as the producer.
For HTTP
microservice architecture, OpenTelemetry will automatically pass the carrier
via traceparent
headers and restore the context.
In an event-driven architecture, the parent span may not have the output on completion. This can make it difficult for reviewers to understand the workflow context. To address this, associate the span_id
with your unique identifier (e.g., database row ID) using this method:
agiflow.associate_trace(
id, # Unique ID linked to trace_id
span_id # Unique ID linked to span_id
);
Then update the span using your database ID:
agiflow.update_span(
id, # Unique ID linked to span_id
{
"output": "...',
}
);
Agiflow supports adding user feedback via the backend API. Here is how to do it:
To provide feedback on past actions, you need to provide extra information, such as
message Id
, to correctly associate user feedback with the right action.
agiflow.associate_trace(
id, # Unique ID linked to trace_id
span_id # Unique ID linked to span_id
);
Later, when a user provides feedback, you can simply do:
agiflow.report_score(
id, # action_id or unique ID
0.6 # Normalized score
);
You can asynchronously invoke the feedback widget on the frontend to collect user feedback.
This comprehensive documentation provides an overview of setting up and using the agiflow-sdk
, including installation, setup, tracing, and user feedback. If you would like to add additional libraries support, please see contribution guideline, we would love to have your support. Thanks!
FAQs
Agiflow Software Development Kit (SDK) for Python, support LLM APIs and Frameworks tracing with Opentelemetry and more.
We found that agiflow-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.