Core domain type definitions for the Embabel Agent Framework, providing foundational data classes and interfaces for agent-based AI workflows including content assets, research entities, and person types with Jackson serialization and PromptContributor capabilities.
Domain models for representing people in agent workflows.
@JsonDeserialize(as = PersonImpl::class)
interface Person {
val name: String
}Properties:
name: String - Person's nameJackson: @JsonDeserialize(as = PersonImpl::class) - Automatically uses PersonImpl when deserializing JSON to Person interface
Default implementation of Person interface.
data class PersonImpl(
override val name: String
) : PersonProperties:
name: String - Person's name (from Person interface)Methods:
equals(other: Any?): Boolean - Structural equality (data class)hashCode(): Int - Hash code (data class)toString(): String - Format: "PersonImpl(name=...)" (data class)copy(name: String = this.name): PersonImpl - Create copy (data class)import com.embabel.agent.domain.library.Person
import com.embabel.agent.domain.library.PersonImpl
// Create person
val person: Person = PersonImpl("John Doe")
println(person.name) // "John Doe"
// Direct instantiation
val person2 = PersonImpl("Alice Smith")
println(person2) // PersonImpl(name=Alice Smith)// Function accepting Person interface
fun greet(person: Person) {
println("Hello, ${person.name}!")
}
val person = PersonImpl("Alice")
greet(person) // Hello, Alice!
// Collections
val people: List<Person> = listOf(
PersonImpl("Alice"),
PersonImpl("Bob"),
PersonImpl("Charlie")
)
people.forEach { println(it.name) }val p1 = PersonImpl("Alice")
val p2 = PersonImpl("Alice")
val p3 = PersonImpl("Bob")
// Structural equality
println(p1 == p2) // true
println(p1 == p3) // false
// Copy with modifications
val renamed = p1.copy(name = "Alice Smith")
// Destructuring
val (name) = p1
println(name) // "Alice"val people = listOf(
PersonImpl("Alice"),
PersonImpl("Bob"),
PersonImpl("Charlie")
)
// Map names
val names = people.map { it.name }
// ["Alice", "Bob", "Charlie"]
// Filter
val aNames = people.filter { it.name.startsWith("A") }
// Set operations (structural equality)
val set1 = setOf(PersonImpl("Alice"), PersonImpl("Bob"))
val set2 = setOf(PersonImpl("Alice"), PersonImpl("Charlie"))
val intersection = set1.intersect(set2)
// [PersonImpl(name=Alice)]import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
val mapper = jacksonObjectMapper()
val person = PersonImpl("Jane Doe")
// Serialize
val json = mapper.writeValueAsString(person)
// {"name":"Jane Doe"}
// Deserialize to PersonImpl
val asPerson = mapper.readValue(json, PersonImpl::class.java)
// Deserialize to Person interface (uses PersonImpl automatically)
val asInterface: Person = mapper.readValue(json, Person::class.java)
println(asInterface::class.simpleName) // "PersonImpl"JSON Format:
{
"name": "Jane Doe"
}Extend Person interface for additional properties:
data class PersonWithEmail(
override val name: String,
val email: String
) : Person
data class PersonWithDetails(
override val name: String,
val email: String,
val phone: String?,
val department: String
) : Person
// Usage
val employee: Person = PersonWithDetails(
name = "Alice Smith",
email = "alice@example.com",
phone = "+1-555-0100",
department = "Engineering"
)
// Works with Person interface
fun sendNotification(person: Person, message: String) {
println("Sending to ${person.name}: $message")
}
sendNotification(employee, "Meeting at 3pm")import com.embabel.agent.domain.library.*
data class BlogAuthor(
override val name: String,
val bio: String
) : Person
val author = BlogAuthor(
name = "Dr. Jane Smith",
bio = "AI researcher and writer"
)
val blog = Blog(
title = "Understanding AI Agents",
author = author.name,
content = "AI agents are autonomous systems..."
)data class Researcher(
override val name: String,
val affiliation: String
) : Person
val researchers = listOf(
Researcher("Dr. Alice", "MIT"),
Researcher("Dr. Bob", "Stanford")
)
val report = ResearchReport(
topic = "Collaborative AI Research",
content = """
Research by: ${researchers.joinToString(", ") { "${it.name} (${it.affiliation})" }}
Findings...
""".trimIndent(),
links = listOf()
)data class TeamMember(
override val name: String,
val role: String,
val lead: Boolean = false
) : Person
val team = listOf(
TeamMember("Alice", "Engineer", lead = true),
TeamMember("Bob", "Designer"),
TeamMember("Charlie", "QA")
)
val lead = team.find { it.lead }
println("Team lead: ${lead?.name}")
val engineers = team.filter { it.role == "Engineer" }data class ContentCreator(
override val name: String,
val specialty: String
) : Person
val creator = ContentCreator("Jane Doe", "Technical Writing")
val blog = Blog(
title = "Getting Started",
author = creator.name,
content = "...",
keywords = setOf("tutorial", creator.specialty.lowercase())
)data class PersonWithContext(
override val name: String,
val role: String,
val background: String
) : Person {
fun toPromptContext(): String = """
Name: $name
Role: $role
Background: $background
""".trimIndent()
}
val person = PersonWithContext(
name = "Dr. Smith",
role = "AI Researcher",
background = "10 years in machine learning"
)
val prompt = """
Consider this person:
${person.toPromptContext()}
What research topics would be relevant?
""".trimIndent()Person (interface)
└── PersonImpl (default data class)Custom Extensions:
Person (interface)
├── PersonImpl (default)
├── PersonWithEmail (custom)
├── PersonWithDetails (custom)
├── BlogAuthor (custom)
├── Researcher (custom)
├── TeamMember (custom)
└── ContentCreator (custom)tessl i tessl/maven-com-embabel-agent--embabel-agent-domain@0.3.0